From 3e653087894d1fc851ab0e82b645e08c9be5b375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Thu, 28 Dec 2023 19:37:52 +0000 Subject: [PATCH] migrations: ignore unique constraint violation --- nexus/catalog/src/lib.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/nexus/catalog/src/lib.rs b/nexus/catalog/src/lib.rs index 32ee57c034..d24338b62c 100644 --- a/nexus/catalog/src/lib.rs +++ b/nexus/catalog/src/lib.rs @@ -24,18 +24,31 @@ pub struct Catalog { } async fn run_migrations(client: &mut Client) -> anyhow::Result<()> { - let migration_report = embedded::migrations::runner() + let migration = embedded::migrations::runner() .run_async(client) .await - .context("Failed to run migrations")?; - for migration in migration_report.applied_migrations() { - tracing::info!( - "Migration Applied - Name: {}, Version: {}", - migration.name(), - migration.version() - ); + .context("Failed to run migrations"); + match migration { + Ok(migration_report) => { + for migration in migration_report.applied_migrations() { + tracing::info!( + "Migration Applied - Name: {}, Version: {}", + migration.name(), + migration.version() + ); + } + Ok(()) + } + Err(err) => { + let errstr = err.to_string(); + if errstr.contains("duplicate key value violates unique constraint \"refinery_schema_history_pkey\"") || + errstr.contains("(typname, typnamespace)=(refinery_schema_history, 2200) already exists") { + Ok(()) + } else { + Err(err) + } + } } - Ok(()) } #[derive(Debug, Copy, Clone)]