d4122c8f95
Add pomodoro timer with goal notifications, writing streak milestones, and knowledge injection logging with UI previews across AI writing flows. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { describe, it, expect, afterEach } from 'vitest'
|
|
import { DatabaseSync } from 'node:sqlite'
|
|
import { migrate } from '../../src/main/db/migrate'
|
|
import schemaV1 from '../../src/main/db/schema-v1.sql?raw'
|
|
import schemaV2 from '../../src/main/db/schema-v2.sql?raw'
|
|
import type { SqliteDb } from '../../src/main/db/types'
|
|
|
|
function tableExists(db: SqliteDb, name: string): boolean {
|
|
const row = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(name)
|
|
return row != null
|
|
}
|
|
|
|
describe('migrate v3', () => {
|
|
let db: SqliteDb
|
|
|
|
afterEach(() => {
|
|
db?.close()
|
|
})
|
|
|
|
it('applies v3 on fresh database', () => {
|
|
db = new DatabaseSync(':memory:')
|
|
migrate(db)
|
|
|
|
expect(tableExists(db, 'ai_sessions')).toBe(true)
|
|
expect(tableExists(db, 'ai_messages')).toBe(true)
|
|
|
|
const version = db.prepare('SELECT MAX(version) AS v FROM schema_version').get() as { v: number }
|
|
expect(version.v).toBe(8)
|
|
})
|
|
|
|
it('migrates existing v2 database to v3', () => {
|
|
db = new DatabaseSync(':memory:')
|
|
db.exec(`CREATE TABLE IF NOT EXISTS schema_version (
|
|
version INTEGER PRIMARY KEY,
|
|
applied_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
description TEXT
|
|
)`)
|
|
db.exec(schemaV1)
|
|
db.exec(schemaV2)
|
|
db.prepare('INSERT INTO schema_version (version, description) VALUES (?, ?)').run(1, 'initial schema')
|
|
db.prepare('INSERT INTO schema_version (version, description) VALUES (?, ?)').run(2, 'P2 schema')
|
|
|
|
migrate(db)
|
|
|
|
const tables = db
|
|
.prepare("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")
|
|
.all() as { name: string }[]
|
|
expect(tables.map((t) => t.name)).toContain('ai_sessions')
|
|
expect(tables.map((t) => t.name)).toContain('ai_messages')
|
|
|
|
const version = db.prepare('SELECT MAX(version) AS v FROM schema_version').get() as { v: number }
|
|
expect(version.v).toBe(8)
|
|
})
|
|
})
|