Skip to content

Commit

Permalink
Test and allow CITEXT <-> TEXT casts on postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule committed Jul 1, 2021
1 parent 37647d3 commit 4c0c008
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Expand Up @@ -316,7 +316,7 @@ fn native_type_change_riskyness(previous: PostgresType, next: PostgresType) -> O
_ => NotCastable,
},
Text => match next {
Text | VarChar(None) => SafeCast,
Text | VarChar(None) | Citext => SafeCast,
VarChar(_) | Char(_) => RiskyCast,
_ => NotCastable,
},
Expand Down
@@ -1,4 +1,4 @@
use migration_engine_tests::sync_test_api::*;
use migration_engine_tests::{sql::ResultSetExt, sync_test_api::*};
use sql_schema_describer::ColumnTypeFamily;
use std::fmt::Write;

Expand Down Expand Up @@ -328,3 +328,56 @@ fn postgres_apply_migrations_errors_give_precise_location_at_the_beginning_of_fi
let first_segment = err.split_terminator("DbError {").next().unwrap();
expectation.assert_eq(first_segment)
}

#[test_connector(tags(Postgres))]
fn citext_to_text_and_back_works(api: TestApi) {
api.raw_cmd("CREATE EXTENSION citext;");

let dm1 = r#"
datasource pg {
provider = "postgres"
url = env("DBURL")
}
model User {
id Int @id @default(autoincrement())
name String @pg.Text
}
"#;

let dm2 = r#"
datasource pg {
provider = "postgres"
url = env("DBURL")
}
model User {
id Int @id @default(autoincrement())
name String @pg.Citext
}
"#;

api.schema_push(dm1).send_sync().assert_green_bang();

api.raw_cmd("INSERT INTO \"User\" (name) VALUES ('myCat'), ('myDog'), ('yourDog');");

// TEXT -> CITEXT
api.schema_push(dm2)
.send_sync()
.assert_green_bang()
.assert_has_executed_steps();

api.dump_table("User")
.assert_row_count(3)
.assert_first_row(|row| row.assert_text_value("name", "myCat"));

// CITEXT -> TEXT
api.schema_push(dm1)
.send_sync()
.assert_green_bang()
.assert_has_executed_steps();

api.dump_table("User")
.assert_row_count(3)
.assert_first_row(|row| row.assert_text_value("name", "myCat"));
}

0 comments on commit 4c0c008

Please sign in to comment.