feat(db): 0000 站点域——sites/site_config_revisions + 唯一约束
drizzle-kit 首个迁移从 0000 起编号(计划文案写 0001,以实际产出为准)。 迁移文件 + meta/_journal.json + snapshot 一并入库。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// 站点域集成测试:约束在真 PG 上生效(唯一键、复合唯一键)。
|
||||
// 简易内联版——Task 13 收敛为公共 helper;本任务只需连库即可(getDb 从 apps/api 源码导入)。
|
||||
// 生命周期纪律:随机 key 插入 + finally 清理,可重复运行不残留脏数据。
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { getDb } from '../../apps/api/src/db/client.js'
|
||||
|
||||
describe('站点域约束', () => {
|
||||
it('sites.key 唯一;site_config_revisions (site_id,version) 唯一', async () => {
|
||||
const db = getDb()
|
||||
const key = `fixture-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
const r = (await db.execute(`insert into sites (id, key, name, default_locale, production_origin)
|
||||
values (gen_random_uuid(), '${key}', 'Fixture', 'en', 'https://fixture.example') returning id`)) as any
|
||||
const siteId = r[0].id
|
||||
try {
|
||||
await expect(db.execute(`insert into sites (id, key, name, default_locale, production_origin)
|
||||
values (gen_random_uuid(), '${key}', 'Dup', 'en', 'https://x.example')`)).rejects.toThrow()
|
||||
await db.execute(`insert into site_config_revisions (id, site_id, version, data, checksum)
|
||||
values (gen_random_uuid(), '${siteId}', 1, '{"a":1}', 'c1')`)
|
||||
await expect(db.execute(`insert into site_config_revisions (id, site_id, version, data, checksum)
|
||||
values (gen_random_uuid(), '${siteId}', 1, '{"a":2}', 'c2')`)).rejects.toThrow()
|
||||
} finally {
|
||||
await db.execute(`delete from site_config_revisions where site_id = '${siteId}'`)
|
||||
await db.execute(`delete from sites where id = '${siteId}'`)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user