From 5dcda6c9e18f1b627701a3c5cc848179f7c78779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Sat, 30 Dec 2023 20:30:38 +0000 Subject: [PATCH] Create table outside transaction so ignored unique violation doesn't block rest of transaction --- nexus/catalog/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nexus/catalog/src/lib.rs b/nexus/catalog/src/lib.rs index 69bf8986be..df5d51bd2b 100644 --- a/nexus/catalog/src/lib.rs +++ b/nexus/catalog/src/lib.rs @@ -41,7 +41,9 @@ impl<'a> Migration<'a> { return Err(anyhow!("migration filename must contain __")); }; let Ok(version) = f[..__idx].parse() else { - return Err(anyhow!("migration filename must have number between V & __")); + return Err(anyhow!( + "migration filename must have number between V & __" + )); }; let name = &f[__idx + 2..]; Ok(Self { @@ -128,8 +130,8 @@ impl Catalog { .map(Migration::new) .collect::>>()?; migrations.sort(); - let tx = self.pg.transaction().await?; - let create = tx + let create = self + .pg .query( "create table if not exists refinery_schema_history(\ version int4 primary key, name text, applied_on text, checksum text)", @@ -142,6 +144,7 @@ impl Catalog { } } + let tx = self.pg.transaction().await?; tx.execute( "lock table refinery_schema_history in share update exclusive mode", &[],