feat(schema): 001 — spaces, projects, tasks with check constraints
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
36
tests/db/migration_001.test.js
Normal file
36
tests/db/migration_001.test.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { describe, it, expect, beforeAll } from 'vitest';
|
||||
import { resetDb, withClient } from '../helpers/db.js';
|
||||
import { migrateUp } from '../../lib/db/migrate.js';
|
||||
|
||||
describe('migration 001 — core', () => {
|
||||
beforeAll(async () => { await resetDb(); await migrateUp(); });
|
||||
|
||||
it('creates spaces, projects, tasks tables', async () => {
|
||||
await withClient(async (c) => {
|
||||
for (const t of ['spaces', 'projects', 'tasks']) {
|
||||
const { rows } = await c.query(
|
||||
`SELECT to_regclass('public.' || $1) AS t;`, [t]
|
||||
);
|
||||
expect(rows[0].t).toBe(t);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('enforces UNIQUE(space_id, slug) on projects', async () => {
|
||||
await withClient(async (c) => {
|
||||
const { rows: [s] } = await c.query(
|
||||
`INSERT INTO spaces(slug, name) VALUES('test', 'Test') RETURNING id;`
|
||||
);
|
||||
await c.query(
|
||||
`INSERT INTO projects(space_id, slug, name) VALUES($1, 'a', 'A');`,
|
||||
[s.id]
|
||||
);
|
||||
await expect(
|
||||
c.query(
|
||||
`INSERT INTO projects(space_id, slug, name) VALUES($1, 'a', 'B');`,
|
||||
[s.id]
|
||||
)
|
||||
).rejects.toThrow(/duplicate key/i);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user