From 527efb510fcba2f8f4bba024184354cdb90dd193 Mon Sep 17 00:00:00 2001 From: bsodfather Date: Tue, 1 Sep 2026 20:30:09 +0300 Subject: [PATCH] fix(deploy): distinguish core migration drift --- crates/crank-registry/src/migrations/authority.rs | 4 ++-- .../crank-registry/tests/integration/migrations.rs | 14 ++++++++++++++ scripts/restore-community.sh | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/crank-registry/src/migrations/authority.rs b/crates/crank-registry/src/migrations/authority.rs index 3d629e1..873d428 100644 --- a/crates/crank-registry/src/migrations/authority.rs +++ b/crates/crank-registry/src/migrations/authority.rs @@ -410,7 +410,7 @@ async fn inspect(connection: &mut PgConnection) -> Result Result<(), Migra if rows.len() != 1 { return Err(MigrationError::new( "partial_sequence", - "preflight.core", + "preflight.core_cardinality", None, "restore_known_good_backup", )); diff --git a/crates/crank-registry/tests/integration/migrations.rs b/crates/crank-registry/tests/integration/migrations.rs index cf0cc3f..866bfa0 100644 --- a/crates/crank-registry/tests/integration/migrations.rs +++ b/crates/crank-registry/tests/integration/migrations.rs @@ -937,6 +937,20 @@ async fn any_owned_relation_without_core_ledger_is_partial() { .unwrap(); let error = MigrationAuthority::preflight(&pool).await.unwrap_err(); assert_eq!(error.code(), "partial_sequence"); + assert_eq!(error.stage(), "preflight.core_missing"); +} +#[tokio::test] +async fn empty_core_ledger_is_reported_separately() { + let database_url = crank_test_support::postgres_schema_url("test_empty_core_ledger").await; + let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); + MigrationAuthority::apply(&pool).await.unwrap(); + sqlx::query("delete from __crank_core_migrations") + .execute(&pool) + .await + .unwrap(); + let error = MigrationAuthority::preflight(&pool).await.unwrap_err(); + assert_eq!(error.code(), "partial_sequence"); + assert_eq!(error.stage(), "preflight.core_cardinality"); } #[tokio::test] async fn current_ledger_with_structural_drift_fails_closed() { diff --git a/scripts/restore-community.sh b/scripts/restore-community.sh index 2065479..4c1b10f 100755 --- a/scripts/restore-community.sh +++ b/scripts/restore-community.sh @@ -49,13 +49,18 @@ postgres_port="$(env_value POSTGRES_PORT 5432)" postgres_db="$(env_value POSTGRES_DB crank)" postgres_user="$(env_value POSTGRES_USER crank)" postgres_password="$(env_value POSTGRES_PASSWORD)" +docker run --rm \ + -v "$backup_dir:/backup:ro" \ + postgres:16-alpine \ + pg_restore --list /backup/postgres.dump >/dev/null docker run --rm --network host \ -e PGPASSWORD="$postgres_password" \ -v "$backup_dir:/backup:ro" \ postgres:16-alpine \ pg_restore --host "$postgres_host" --port "$postgres_port" \ --username "$postgres_user" --dbname "$postgres_db" \ - --clean --if-exists --no-owner --no-privileges /backup/postgres.dump + --clean --if-exists --no-owner --no-privileges \ + --single-transaction --exit-on-error /backup/postgres.dump admin_container="$(compose ps -aq admin-api)" storage_root="$(env_value CRANK_STORAGE_ROOT /var/lib/crank/storage)"