eternalfest_db_schema/
lib.rs

1use etwin_squirrel::SchemaResolver;
2pub use etwin_squirrel::SchemaStateRef;
3use include_dir::{include_dir, Dir};
4use lazy_static::lazy_static;
5use sqlx::PgPool;
6use std::error::Error;
7
8const DB_SCRIPTS: Dir = include_dir!("$CARGO_MANIFEST_DIR/scripts");
9
10lazy_static! {
11  static ref SQUIRREL: SchemaResolver = SchemaResolver::new(&DB_SCRIPTS);
12}
13
14pub async fn get_state(db: &PgPool) -> Result<SchemaStateRef<'static>, Box<dyn Error>> {
15  SQUIRREL.get_state(db).await
16}
17
18pub async fn empty(db: &PgPool) -> Result<(), Box<dyn Error>> {
19  SQUIRREL.empty(db).await
20}
21
22pub async fn force_create_latest(db: &PgPool, void: bool) -> Result<(), Box<dyn Error>> {
23  SQUIRREL.force_create_latest(db, void).await
24}
25
26// pub async fn upgrade_to_latest(db: &PgPool) -> Result<(), Box<dyn Error>> {
27//   let start = SQUIRREL.get_state(db).await?;
28//   let end = SQUIRREL.get_latest();
29//   let migration = SQUIRREL
30//     .create_migration(start, end, MigrationDirection::UpgradeOnly);
31//   let migration = migration.ok_or_else(|| "FailedToComputeMigrationToLatest".into())?;
32//   SQUIRREL.apply_migration(db, &migration).await
33// }
34
35pub async fn force_create(db: &PgPool, state: SchemaStateRef<'static>, void: bool) -> Result<(), Box<dyn Error>> {
36  SQUIRREL.force_create(db, state, void).await
37}