mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-27 16:59:23 +08:00
🐛 fix(table-designer): 修复 DuckDB 表设计主键保存失效
- 为 DuckDB 表结构变更补充 ADD PRIMARY KEY 预览 SQL - 保存前拦截已有主键表的主键替换与删除,避免假成功 - 补充 DuckDB 主键变更判定与 schema SQL 回归测试
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { EditableColumnSnapshot } from './tableDesignerSchemaSql';
|
||||
import { summarizeDuckDbPrimaryKeyChange } from './tableDesignerDuckDbPrimaryKey';
|
||||
|
||||
const col = (overrides: Partial<EditableColumnSnapshot>): EditableColumnSnapshot => ({
|
||||
_key: overrides._key || 'id',
|
||||
name: overrides.name || 'id',
|
||||
type: overrides.type || 'BIGINT',
|
||||
nullable: overrides.nullable || 'NO',
|
||||
default: overrides.default || '',
|
||||
extra: overrides.extra || '',
|
||||
comment: overrides.comment || '',
|
||||
key: overrides.key || '',
|
||||
isAutoIncrement: overrides.isAutoIncrement || false,
|
||||
});
|
||||
|
||||
describe('tableDesignerDuckDbPrimaryKey', () => {
|
||||
it('treats first primary key addition as supported', () => {
|
||||
const summary = summarizeDuckDbPrimaryKeyChange(
|
||||
[col({ _key: 'id', key: '' })],
|
||||
[col({ _key: 'id', key: 'PRI' })],
|
||||
);
|
||||
|
||||
expect(summary).toEqual({
|
||||
hasChange: true,
|
||||
isAddingPrimaryKey: true,
|
||||
isUnsupportedChange: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('treats replacing an existing primary key as unsupported', () => {
|
||||
const summary = summarizeDuckDbPrimaryKeyChange(
|
||||
[col({ _key: 'id', key: 'PRI' }), col({ _key: 'name', name: 'name', key: '' })],
|
||||
[col({ _key: 'id', key: '' }), col({ _key: 'name', name: 'name', key: 'PRI' })],
|
||||
);
|
||||
|
||||
expect(summary).toEqual({
|
||||
hasChange: true,
|
||||
isAddingPrimaryKey: false,
|
||||
isUnsupportedChange: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user