mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-26 00:11:43 +08:00
- 为 Oracle 建表 DDL 追加注释前补齐语句结束符并保留空行分隔 - 修复 COMMENT ON TABLE/COLUMN 与 CREATE TABLE 粘连导致复制后无法直接执行的问题 - 补充后端 Oracle 建表语句与前端 DDL 格式化回归测试
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { formatDdlForDisplay } from './ddlFormat';
|
|
|
|
describe('formatDdlForDisplay', () => {
|
|
it('formats DuckDB create table SQL into multiline output', () => {
|
|
const raw = 'CREATE TABLE customers(customer_id BIGINT, customer_code VARCHAR, city VARCHAR, tier VARCHAR, signup_date DATE, lifetime_value DECIMAL(12,2), PRIMARY KEY(customer_id));';
|
|
|
|
const formatted = formatDdlForDisplay(raw, 'duckdb');
|
|
|
|
expect(formatted).toContain('CREATE TABLE customers (');
|
|
expect(formatted).toContain('customer_id BIGINT,');
|
|
expect(formatted).toContain('PRIMARY KEY (customer_id)');
|
|
expect(formatted).toContain('\n');
|
|
});
|
|
|
|
it('returns original text when formatter cannot parse the statement', () => {
|
|
const raw = 'not valid ddl(';
|
|
|
|
expect(formatDdlForDisplay(raw, 'duckdb')).toBe(raw);
|
|
});
|
|
|
|
it('keeps Oracle comment statements separated from create table DDL', () => {
|
|
const raw = `CREATE TABLE "H2"."S_BUSI" (
|
|
"ID" NUMBER
|
|
) TABLESPACE "H2DB";
|
|
|
|
COMMENT ON TABLE "H2"."S_BUSI" IS '业务机构信息';
|
|
COMMENT ON COLUMN "H2"."S_BUSI"."ID" IS '主键';`;
|
|
|
|
const formatted = formatDdlForDisplay(raw, 'oracle');
|
|
|
|
expect(formatted).toContain('TABLESPACE "H2DB";\n\nCOMMENT ON TABLE "H2"."S_BUSI"');
|
|
expect(formatted).toContain(`COMMENT ON COLUMN "H2"."S_BUSI"."ID" IS '主键';`);
|
|
});
|
|
});
|