Skip to content

Commit

Permalink
[CDB] Introspect Json Defaults (prisma#2585)
Browse files Browse the repository at this point in the history
case insensitive equality for the data type suffices
  • Loading branch information
do4gr authored Jan 14, 2022
1 parent 6761f92 commit e099c30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,28 @@ async fn introspecting_now_functions(api: &TestApi) -> TestResult {

Ok(())
}

#[test_connector(tags(CockroachDb))]
async fn introspecting_json_defaults_on_cockroach(api: &TestApi) -> TestResult {
let setup = indoc! {r#"
CREATE TABLE "A" (
id INTEGER NOT NULL Primary Key,
json Json Default '[]'::json,
jsonb JsonB Default '{}'::jsonb
);
"#};
api.raw_cmd(setup).await;

let expectation = expect![[r#"
model A {
id Int @id
json Json? @default("[]")
jsonb Json? @default("{}")
}
"#]];

expectation.assert_eq(&api.introspect_dml().await?);

Ok(())
}
5 changes: 4 additions & 1 deletion libs/sql-schema-describer/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,10 @@ fn unsuffix_default_literal<'a, T: AsRef<str>>(literal: &'a str, expected_suffix
let captures = POSTGRES_DATA_TYPE_SUFFIX_RE.captures(literal)?;
let suffix = captures.get(3).unwrap().as_str();

if !expected_suffixes.iter().any(|expected| expected.as_ref() == suffix) {
if !expected_suffixes
.iter()
.any(|expected| expected.as_ref().eq_ignore_ascii_case(suffix))
{
return None;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl fmt::Display for ConnectorVersion {
},
Self::Sqlite => "SQLite".to_string(),
Self::Vitess(v) => match v {
Some(v) => format!("Vitess ({})", v.to_string()),
Some(v) => format!("Vitess ({})", v),
None => "Vitess (unknown)".to_string(),
},
Self::CockroachDb => "CockroachDB".to_string(),
Expand Down

0 comments on commit e099c30

Please sign in to comment.