fix(kingbase): preserve SQLServer identity metadata
This commit is contained in:
1 parent
002dbbf602
commit
904863a57c
6 files changed
+192
-2
No files matched your search
@@ -16,12 +16,24 @@ import {
|
||||
isMysqlEnumDataType,
|
||||
isSqlServerIdentityCompatibleDataType,
|
||||
mysqlEnumDataType,
|
||||
parseExtraToColumnExtra,
|
||||
rehydrateColumnDraftsFromMetadata,
|
||||
restoreDamengLengthUnitsAfterSave,
|
||||
splitDataType,
|
||||
} from "@/lib/table/tableStructureEditorState";
|
||||
|
||||
describe("tableStructureEditorState", () => {
|
||||
it("parses Kingbase SQLServer compatibility identity metadata", () => {
|
||||
expect(parseExtraToColumnExtra("identity(10, 2)", "kingbase")).toEqual({
|
||||
autoIncrement: true,
|
||||
identity: { seed: 10, increment: 2 },
|
||||
});
|
||||
expect(parseExtraToColumnExtra("generated always as identity", "kingbase")).toEqual({
|
||||
identity: { generation: "ALWAYS" },
|
||||
});
|
||||
expect(parseExtraToColumnExtra("identity(1,1)", "postgres")).toEqual({});
|
||||
});
|
||||
|
||||
it("keeps mysql unsigned attributes in the editable base type", () => {
|
||||
expect(splitDataType("int(11) unsigned")).toEqual({ baseType: "int unsigned", params: "11" });
|
||||
expect(splitDataType("bigint(20) unsigned zerofill")).toEqual({
|
||||
|
||||
@@ -477,6 +477,16 @@ export function parseExtraToColumnExtra(extra: string | null | undefined, databa
|
||||
result.identity.seed = Number(sequenceMatch[1]);
|
||||
result.identity.increment = Number(sequenceMatch[2]);
|
||||
}
|
||||
} else if (databaseType === "kingbase") {
|
||||
// SQLServer compatibility reports IDENTITY(seed, increment) instead of PostgreSQL identity syntax.
|
||||
const sqlServerIdentityMatch = lower.match(/identity\s*\(\s*(-?\d+)\s*,\s*(-?\d+)\s*\)/i);
|
||||
if (sqlServerIdentityMatch) {
|
||||
result.autoIncrement = true;
|
||||
result.identity = {
|
||||
seed: Number(sqlServerIdentityMatch[1]),
|
||||
increment: Number(sqlServerIdentityMatch[2]),
|
||||
};
|
||||
}
|
||||
}
|
||||
} else if (databaseType === "sqlserver") {
|
||||
if (lower.includes("identity")) {
|
||||
|
||||
Reference in new issue
Block a user