mirror of
https://github.com/sinanyuntu/trade-message-center.git
synced 2026-09-17 13:22:11 +08:00
46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
// 验证渲染卡片补全使用独立、带备注的追加迁移。
|
|
|
|
import assert from "node:assert/strict";
|
|
import { existsSync } from "node:fs";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
|
|
import { ONETALK_INITIAL_HISTORY_GENERATION } from "@trade-message-center/onetalk-contract";
|
|
|
|
import { migrationDirectory } from "../src/database/migration-config.ts";
|
|
import { ONETALK_SCHEMA_INITIAL_HISTORY_GENERATION } from "../src/database/schema/onetalk.ts";
|
|
|
|
test("keeps the CJS-safe schema history default aligned with the shared contract", () => {
|
|
assert.equal(ONETALK_SCHEMA_INITIAL_HISTORY_GENERATION, ONETALK_INITIAL_HISTORY_GENERATION);
|
|
});
|
|
|
|
test("drops obsolete audit columns and expands the rendered-card kinds without rewriting history", async () => {
|
|
const sourceMigrationUrl = new URL(`../${migrationDirectory}/`, import.meta.url);
|
|
const migrationUrl = existsSync(sourceMigrationUrl)
|
|
? sourceMigrationUrl
|
|
: new URL(`../../${migrationDirectory}/`, import.meta.url);
|
|
const migration015 = await readFile(new URL("0015_wild_toad_men.sql", migrationUrl), "utf8");
|
|
const migration016 = await readFile(
|
|
new URL("0016_optimal_imperial_guard.sql", migrationUrl),
|
|
"utf8",
|
|
);
|
|
|
|
for (const column of [
|
|
"first_confirmed_at",
|
|
"last_observed_at",
|
|
"last_conflicting_fingerprint",
|
|
"last_conflict_observed_at_ms",
|
|
])
|
|
assert.match(
|
|
migration015,
|
|
new RegExp(`ALTER TABLE "onetalk_rendered_card_content" DROP COLUMN "${column}"`, "i"),
|
|
);
|
|
assert.doesNotMatch(migration015, /\b(?:DELETE|TRUNCATE|CREATE\s+TABLE|CONSTRAINT)\b/i);
|
|
assert.doesNotMatch(migration016, /\b(?:DELETE|TRUNCATE|CREATE\s+TABLE|DROP\s+COLUMN)\b/i);
|
|
assert.match(migration016, /DROP CONSTRAINT "onetalk_rendered_card_content_v1_chk"/i);
|
|
assert.match(
|
|
migration016,
|
|
/ADD CONSTRAINT "onetalk_rendered_card_content_v1_chk" CHECK .*not .*\? 'kind'/is,
|
|
);
|
|
});
|