29 lines
866 B
JavaScript
29 lines
866 B
JavaScript
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import { resetDb, withClient } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
|
|
describe('migrate', () => {
|
|
beforeAll(async () => { await resetDb(); });
|
|
|
|
it('creates schema_migrations table on first run', async () => {
|
|
await migrateUp();
|
|
await withClient(async (c) => {
|
|
const { rows } = await c.query(
|
|
`SELECT to_regclass('public.schema_migrations') AS t;`
|
|
);
|
|
expect(rows[0].t).toBe('schema_migrations');
|
|
});
|
|
});
|
|
|
|
it('is idempotent — second run is a no-op', async () => {
|
|
await migrateUp();
|
|
await migrateUp();
|
|
await withClient(async (c) => {
|
|
const { rows } = await c.query(
|
|
`SELECT count(*)::int AS n FROM schema_migrations;`
|
|
);
|
|
expect(rows[0].n).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|
|
});
|