From 3767f4a83b2078d09f12053f40682e91ad99bdd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E4=B8=AB=E8=AE=B2=E6=A2=B5?= Date: Sun, 13 Sep 2026 02:11:17 +0800 Subject: [PATCH] feat(sqlite): support autoincrement primary key in structure editor --- .../structure/TableStructureEditor.vue | 18 +++ .../lib/table/tableStructureEditorState.ts | 7 +- crates/dbx-core/src/schema_diff.rs | 135 +++++++++++++++++- .../dbx-core/src/sql_dialect/ddl_profile.rs | 2 +- .../dbx-core/src/sql_dialect/type_rewrite.rs | 20 ++- .../src/table_structure_sql/column_alter.rs | 15 +- .../src/table_structure_sql/column_format.rs | 7 + .../src/table_structure_sql/create_table.rs | 52 ++++++- .../dbx-core/src/table_structure_sql/tests.rs | 42 ++++++ 9 files changed, 285 insertions(+), 13 deletions(-) diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vue index b2101cf4fd..9159e9418c 100644 --- a/apps/desktop/src/components/structure/TableStructureEditor.vue +++ b/apps/desktop/src/components/structure/TableStructureEditor.vue @@ -1153,6 +1153,18 @@ function setMysqlAutoIncrement(column: EditableStructureColumn, checked: boolean void loadMysqlAutoIncrementCounter(true); } } +function isSqliteAutoIncrement(column: EditableStructureColumn): boolean { + return structureDialect.value === "sqlite" && column.isPrimaryKey && isSqliteIntegerType(column.dataType) && column.extra.autoIncrement === true; +} +function canEditSqliteAutoIncrement(column: EditableStructureColumn): boolean { + return structureDialect.value === "sqlite" && column.isPrimaryKey && isSqliteIntegerType(column.dataType) && !columns.value.some((candidate) => candidate !== column && candidate.isPrimaryKey && candidate.extra.autoIncrement); +} +function setSqliteAutoIncrement(column: EditableStructureColumn, checked: boolean) { + column.extra.autoIncrement = checked; +} +function isSqliteIntegerType(dataType: string): boolean { + return /^(integer|int|tinyint|smallint|mediumint|bigint)$/i.test(dataType.trim().split("(")[0]); +} function onMysqlAutoIncrementInput(event: Event) { const input = event.target as HTMLInputElement; if (/^\d*$/.test(input.value)) { @@ -4698,6 +4710,12 @@ watch( +