mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-26 00:10:31 +08:00
- 为 DuckDB 表结构变更补充 ADD PRIMARY KEY 预览 SQL - 保存前拦截已有主键表的主键替换与删除,避免假成功 - 补充 DuckDB 主键变更判定与 schema SQL 回归测试
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
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,
|
|
});
|
|
});
|
|
});
|