Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 deletions packages/api/tests/runMigrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,50 @@ describe('applyMigrations', () => {
}
});

it('applies the catalog to an empty database, then no-ops', async () => {
const path = `/tmp/dripnex-migrate-${randomUUID()}.db`;
paths.push(path);
const client = createClient({ url: `file:${path}` });
// These two drive a real libsql file database through the entire migration
// catalog — the second one twice. That is legitimately slower than vitest's
// 5s default (3.0s and 7.4s on CI), so they carry their own budget rather
// than the suite carrying a global bump that would mask slow unit tests.
const MIGRATION_TIMEOUT_MS = 30_000;

const first = await applyMigrations(client);
expect(first.skipped).toEqual([]);
expect(first.applied.length + first.recordedExisting.length).toBe(MIGRATIONS.length);
it(
'applies the catalog to an empty database, then no-ops',
async () => {
const path = `/tmp/dripnex-migrate-${randomUUID()}.db`;
paths.push(path);
const client = createClient({ url: `file:${path}` });

const tables = await client.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='plugin_versions'"
);
expect(tables.rows).toHaveLength(1);
const first = await applyMigrations(client);
expect(first.skipped).toEqual([]);
expect(first.applied.length + first.recordedExisting.length).toBe(MIGRATIONS.length);

const second = await applyMigrations(client);
expect(second.applied).toEqual([]);
expect(second.skipped).toEqual(MIGRATIONS.map(m => m.id));
});
const tables = await client.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='plugin_versions'"
);
expect(tables.rows).toHaveLength(1);

it('records migrations that already exist in the schema', async () => {
const path = `/tmp/dripnex-migrate-${randomUUID()}.db`;
paths.push(path);
const client = createClient({ url: `file:${path}` });
await client.execute(
'CREATE TABLE users (id text PRIMARY KEY, email text, created_at text, updated_at text)'
);
const second = await applyMigrations(client);
expect(second.applied).toEqual([]);
expect(second.skipped).toEqual(MIGRATIONS.map(m => m.id));
},
MIGRATION_TIMEOUT_MS
);

const report = await applyMigrations(client);
expect(report.recordedExisting).toContain('0000_chubby_zzzax');
const second = await applyMigrations(client);
expect(second.skipped).toContain('0000_chubby_zzzax');
});
it(
'records migrations that already exist in the schema',
async () => {
const path = `/tmp/dripnex-migrate-${randomUUID()}.db`;
paths.push(path);
const client = createClient({ url: `file:${path}` });
await client.execute(
'CREATE TABLE users (id text PRIMARY KEY, email text, created_at text, updated_at text)'
);

const report = await applyMigrations(client);
expect(report.recordedExisting).toContain('0000_chubby_zzzax');
const second = await applyMigrations(client);
expect(second.skipped).toContain('0000_chubby_zzzax');
},
MIGRATION_TIMEOUT_MS
);
});
Loading