squash database migrations

This commit is contained in:
2025-10-30 17:53:00 +01:00
parent 7fae0e44ac
commit bb34a47fa8
29 changed files with 106 additions and 237 deletions
+5
View File
@@ -37,6 +37,7 @@ use tower::util::ServiceExt;
use uuid::Uuid;
const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
const RESET_SCHEMA_SQL: &str = include_str!("../../migrations/202510300000_initial_schema/down.sql");
static DB_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
@@ -697,6 +698,8 @@ async fn prepare_database(pool: &PgPool) -> Result<()> {
let mut conn = pool
.get()
.map_err(|err| anyhow!("failed to acquire connection: {err}"))?;
let _ = conn.batch_execute(RESET_SCHEMA_SQL);
let _ = conn.batch_execute("DROP TABLE IF EXISTS __diesel_schema_migrations;");
conn.run_pending_migrations(MIGRATIONS)
.map_err(|err| anyhow!("failed to run migrations: {err}"))?;
truncate_all(&mut conn)?;
@@ -721,6 +724,8 @@ fn truncate_all(conn: &mut PgConnection) -> Result<()> {
refresh_tokens, \
tags, \
webdav_tokens, \
webauthn_challenges, \
user_passkeys, \
user_memberships, \
users, \
tenants \