mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-16 11:39:38 +08:00
🐛 fix(table-designer): 修复 DuckDB 表设计主键保存失效
- 为 DuckDB 表结构变更补充 ADD PRIMARY KEY 预览 SQL - 保存前拦截已有主键表的主键替换与删除,避免假成功 - 补充 DuckDB 主键变更判定与 schema SQL 回归测试
This commit is contained in:
38
frontend/src/components/tableDesignerDuckDbPrimaryKey.ts
Normal file
38
frontend/src/components/tableDesignerDuckDbPrimaryKey.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { EditableColumnSnapshot } from './tableDesignerSchemaSql';
|
||||
|
||||
export interface DuckDbPrimaryKeyChangeSummary {
|
||||
hasChange: boolean;
|
||||
isAddingPrimaryKey: boolean;
|
||||
isUnsupportedChange: boolean;
|
||||
}
|
||||
|
||||
const collectPrimaryKeys = (columns: EditableColumnSnapshot[]): string[] => (
|
||||
columns
|
||||
.filter((column) => column.key === 'PRI')
|
||||
.map((column) => String(column._key || '').trim())
|
||||
.filter(Boolean)
|
||||
.sort()
|
||||
);
|
||||
|
||||
export const summarizeDuckDbPrimaryKeyChange = (
|
||||
originalColumns: EditableColumnSnapshot[],
|
||||
columns: EditableColumnSnapshot[],
|
||||
): DuckDbPrimaryKeyChangeSummary => {
|
||||
const originalKeys = collectPrimaryKeys(originalColumns);
|
||||
const nextKeys = collectPrimaryKeys(columns);
|
||||
const hasChange = originalKeys.length !== nextKeys.length || originalKeys.some((key, index) => key !== nextKeys[index]);
|
||||
if (!hasChange) {
|
||||
return {
|
||||
hasChange: false,
|
||||
isAddingPrimaryKey: false,
|
||||
isUnsupportedChange: false,
|
||||
};
|
||||
}
|
||||
|
||||
const isAddingPrimaryKey = originalKeys.length === 0 && nextKeys.length > 0;
|
||||
return {
|
||||
hasChange: true,
|
||||
isAddingPrimaryKey,
|
||||
isUnsupportedChange: !isAddingPrimaryKey,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user