Task 6 of the slice plan. Adds the initial database surface: - m001_initial: notes (with v0.2 columns user_intent, intent_prompted_at, title_edited_by_user, summary_edited_by_user), tags, note_tags (with source ai/user), media, pending_jobs. - migrations/index: forward-only PRAGMA user_version runner that applies pending migrations inside a single transaction. - db/index: openDb() that opens better-sqlite3, enables WAL + foreign_keys, then runs migrations. - migrations.test: schema columns are present at v1; runMigrations is idempotent. Verification: `npx vitest run tests/unit/migrations.test.ts` 2 passed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import Database from 'better-sqlite3';
|
|
import { runMigrations } from '@main/db/migrations/index.js';
|
|
|
|
describe('migrations', () => {
|
|
it('creates schema at version 1 with intent + edited columns', () => {
|
|
const db = new Database(':memory:');
|
|
runMigrations(db);
|
|
const ver = (db.prepare('PRAGMA user_version').get() as { user_version: number }).user_version;
|
|
expect(ver).toBe(1);
|
|
const cols = db.prepare(`PRAGMA table_info(notes)`).all().map((r: any) => r.name);
|
|
expect(cols).toEqual(
|
|
expect.arrayContaining([
|
|
'id', 'raw_text', 'ai_title', 'ai_summary', 'ai_status', 'ai_error',
|
|
'ai_provider', 'ai_generated_at',
|
|
'title_edited_by_user', 'summary_edited_by_user',
|
|
'user_intent', 'intent_prompted_at',
|
|
'created_at', 'updated_at'
|
|
])
|
|
);
|
|
db.close();
|
|
});
|
|
|
|
it('is idempotent', () => {
|
|
const db = new Database(':memory:');
|
|
runMigrations(db);
|
|
runMigrations(db);
|
|
expect((db.prepare('PRAGMA user_version').get() as any).user_version).toBe(1);
|
|
db.close();
|
|
});
|
|
});
|