mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-19 16:16:45 +00:00
fix(table): keep mysql DEFAULT_GENERATED columns copyable
This commit is contained in:
@@ -94,7 +94,9 @@ export function tableDataCopyColumnOptions(databaseType: DatabaseType | undefine
|
||||
function isWritableTableDataCopyColumn(databaseType: DatabaseType | undefined, column: ColumnInfo): boolean {
|
||||
const extra = (column.extra ?? "").toLowerCase();
|
||||
if (databaseType === "mysql") {
|
||||
return !extra.includes("generated");
|
||||
// DEFAULT_GENERATED marks a writable expression default, not a generated column.
|
||||
// Accept both raw EXTRA metadata and the backend's expanded generation clause.
|
||||
return !/\b(?:virtual|stored|persistent)\s+generated\b|\bgenerated\s+always\s+as\s*\(/.test(extra);
|
||||
}
|
||||
if (databaseType === "postgres") {
|
||||
return !extra.includes("generated always as (");
|
||||
|
||||
+2
-2
@@ -72,8 +72,8 @@ test("table data copy uses only writable columns for first-class databases", ()
|
||||
postgresOverridingSystemValue: true,
|
||||
sqlserverIdentityInsert: false,
|
||||
});
|
||||
assert.deepEqual(tableDataCopyColumnOptions("mysql", [{ ...columns[0], extra: "auto_increment" }, { ...columns[1] }, { ...columns[2], extra: "STORED GENERATED" }]), {
|
||||
columns: ["id", "name"],
|
||||
assert.deepEqual(tableDataCopyColumnOptions("mysql", [{ ...columns[0], extra: "auto_increment" }, { ...columns[1] }, { ...columns[2], extra: "STORED GENERATED" }, column("expr_default", "DEFAULT_GENERATED"), column("expr_default_on_update", "DEFAULT_GENERATED on update CURRENT_TIMESTAMP"), column("virtual_full_name", "VIRTUAL GENERATED"), column("stored_full_name", "GENERATED ALWAYS AS (concat(first_name, ' ', last_name)) STORED")]), {
|
||||
columns: ["id", "name", "expr_default", "expr_default_on_update"],
|
||||
postgresOverridingSystemValue: false,
|
||||
sqlserverIdentityInsert: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user