Skip to content

Commit

Permalink
Create table outside transaction so ignored unique violation doesn't …
Browse files Browse the repository at this point in the history
…block rest of transaction
  • Loading branch information
serprex committed Dec 30, 2023
1 parent 488c2f3 commit 5dcda6c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nexus/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -128,8 +130,8 @@ impl Catalog {
.map(Migration::new)
.collect::<anyhow::Result<Vec<_>>>()?;
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)",
Expand All @@ -142,6 +144,7 @@ impl Catalog {
}
}

let tx = self.pg.transaction().await?;
tx.execute(
"lock table refinery_schema_history in share update exclusive mode",
&[],
Expand Down

0 comments on commit 5dcda6c

Please sign in to comment.