mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-20 08:18:52 +00:00
fix(transfer): map datetime to timestamp for h2 targets
This commit is contained in:
@@ -4276,6 +4276,7 @@ pub fn map_column_type(source_type: &str, source_db: &DatabaseType, target_db: &
|
||||
"time" => "TIME".into(),
|
||||
"datetime" => match target_db {
|
||||
target_db if is_postgres_transfer_dialect(target_db) => "TIMESTAMP".into(),
|
||||
DatabaseType::H2 => "TIMESTAMP".into(),
|
||||
DatabaseType::ClickHouse => "DateTime64(6)".into(),
|
||||
_ => "DATETIME".into(),
|
||||
},
|
||||
@@ -13811,6 +13812,26 @@ for line in sys.stdin:
|
||||
assert_eq!(map_column_type("DECIMAL(12,2)", &DatabaseType::Mysql, &DatabaseType::H2), "DECIMAL(12,2)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn h2_transfer_maps_datetime_columns_to_timestamp() {
|
||||
for source_type in ["datetime", "DATETIME", "datetime(6)"] {
|
||||
let columns = vec![test_column("create_at", source_type), test_column("last_update", source_type)];
|
||||
let ddl = generate_create_table_ddl(
|
||||
&columns,
|
||||
"agent_hist",
|
||||
"levault",
|
||||
"PUBLIC",
|
||||
&DatabaseType::H2,
|
||||
&DatabaseType::Mysql,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
assert!(ddl.contains("\"create_at\" TIMESTAMP"), "{ddl}");
|
||||
assert!(ddl.contains("\"last_update\" TIMESTAMP"), "{ddl}");
|
||||
assert!(!ddl.contains("DATETIME"), "{ddl}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn h2_transfer_rewrites_schema_without_changing_literals_or_identifiers() {
|
||||
let sql = r#"CREATE TABLE "Source"."ITEMS" ("NAME" VARCHAR(1024) DEFAULT '"Source".ITEMS');
|
||||
|
||||
Reference in New Issue
Block a user