Skip to content

Commit

Permalink
migrations: ignore unique constraint violation
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Dec 28, 2023
1 parent 5991c38 commit 633ed36
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions nexus/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,35 @@ 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")
|| errstr.contains("type \"refinery_schema_history\" already exists")
{
Ok(())
} else {
Err(err)
}
}
}
Ok(())
}

#[derive(Debug, Copy, Clone)]
Expand Down

0 comments on commit 633ed36

Please sign in to comment.