feat(sqlite): support table structure changes

This commit is contained in:
onenewcode authored and GitHub committed 2026-07-10 20:02:56 +08:00
1 parent f7eec00c8e
commit fc8d407a62
25 files changed
+2320 -50

No files matched your search

@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import { getTableStructureCapabilities } from "@/lib/table/tableStructureCapabilities";
describe("tableStructureCapabilities", () => {
it("uses table rebuilds only for native SQLite connections", () => {
expect(getTableStructureCapabilities("sqlite", "sqlite")).toMatchObject({
alterStrategy: "sqlite-rebuild",
alterExistingColumn: true,
alterType: true,
});
for (const [databaseType, connectionType] of [
["rqlite", "rqlite"],
["turso", "turso"],
["sqlite", "jdbc"],
["sqlite", undefined],
] as const) {
expect(getTableStructureCapabilities(databaseType, connectionType)).toMatchObject({
alterStrategy: "none",
alterExistingColumn: false,
alterType: false,
});
}
});
it("marks databases with native ALTER COLUMN support as direct", () => {
expect(getTableStructureCapabilities("mysql", "mysql").alterStrategy).toBe("direct");
expect(getTableStructureCapabilities("postgres", "postgres").alterStrategy).toBe("direct");
});
});
@@ -3,6 +3,8 @@ import {
combineDataTypeForDatabase,
createColumnDrafts,
dataTypeLengthInputValue,
getDefaultLengthForType,
hasExistingColumnTypeChange,
isDataTypeLengthDisabled,
isMysqlCharacterDataType,
isMysqlEnumDataType,
@@ -96,6 +98,40 @@ describe("tableStructureEditorState", () => {
expect(combineDataTypeForDatabase("mysql", "integer", "11")).toBe("integer(11)");
});
it("does not add MySQL display lengths when choosing SQLite-family types", () => {
for (const databaseType of ["sqlite", "rqlite", "turso"] as const) {
expect(getDefaultLengthForType(databaseType, "integer")).toBe("");
expect(getDefaultLengthForType(databaseType, "real")).toBe("");
expect(combineDataTypeForDatabase(databaseType, "integer", getDefaultLengthForType(databaseType, "integer"))).toBe("integer");
}
expect(getDefaultLengthForType("mysql", "integer")).toBe("11");
});
it("requires a SQLite rebuild only for a retained existing column type change", () => {
const [column] = createColumnDrafts(
[
{
name: "status",
data_type: "integer",
is_nullable: false,
column_default: null,
is_primary_key: false,
extra: null,
},
],
"sqlite",
);
expect(hasExistingColumnTypeChange([column])).toBe(false);
column.name = "state";
expect(hasExistingColumnTypeChange([column])).toBe(false);
column.dataType = "text";
expect(hasExistingColumnTypeChange([column])).toBe(true);
column.markedForDrop = true;
expect(hasExistingColumnTypeChange([column])).toBe(false);
});
it("strips SQL Server metadata parentheses from editable defaults", () => {
const drafts = createColumnDrafts(
[