Skip to content

Commit

Permalink
feat(schema-engine): disabled implicit transaction for batch statemen…
Browse files Browse the repository at this point in the history
…ts starting from CockroachDB v22.2
  • Loading branch information
jkomyno committed Jan 9, 2024
1 parent 98ee706 commit 939a364
Showing 1 changed file with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,47 @@ impl Connection {

let version = quaint.version().await.map_err(quaint_err(&url))?;

if version.map(|v| v.starts_with("CockroachDB CCL v22.2")).unwrap_or(false) {
// first config issue: https://github.com/prisma/prisma/issues/16909
// second config value: Currently at least version 22.2.5, enums are
// not case-sensitive without this.
quaint
.raw_cmd(indoc! {r#"
SET enable_implicit_transaction_for_batch_statements=false;
SET use_declarative_schema_changer=off
"#})
.await
.map_err(quaint_err(&url))?;
if let Some(version) = version {
let cockroach_version_prefix = "CockroachDB CCL v";

let semver: Option<(u8, u8)> = version
.strip_prefix(cockroach_version_prefix)
.map(|v| {
let semver_unparsed: String = v.chars().take_while(|&c| c.is_digit(10) || c == '.').collect();

// we only consider the major and minor version, as the patch version is not interesting for us
semver_unparsed.split_once('.').and_then(|(major, minor_and_patch)| {
let major = major.parse::<u8>().ok();

let minor = minor_and_patch
.chars()
.take_while(|&c| c != '.')
.collect::<String>()
.parse::<u8>()
.ok();

major.zip(minor)
})
})
.flatten();

match semver {
Some((major, minor)) if (major == 22 && minor >= 2) || major >= 23 => {
// we're on 22.2+ or 23+
//
// first config issue: https://github.com/prisma/prisma/issues/16909
// second config value: Currently at least version 22.2.5, enums are
// not case-sensitive without this.
quaint
.raw_cmd(indoc! {r#"
SET enable_implicit_transaction_for_batch_statements=false;
SET use_declarative_schema_changer=off
"#})
.await
.map_err(quaint_err(&url))?;
}
None | Some(_) => (),
};
}

Ok(Connection(quaint))
Expand Down

0 comments on commit 939a364

Please sign in to comment.