d3ro-voice/apps/desktop/tests/helpers/createTestDb.ts
Yun Chan 0a4f5aee64 feat(desktop): two-way cloud sync with mobile and web
Rewrites the desktop mirror as services/sync/SyncEngine: a persistent
outbox, per-account server-clock keyset cursors with paging, pulls that never
overwrite unsent local edits, deletions both ways through sync_tombstones and
per-row failure isolation. It now covers history titles and favorites,
dictionary, every meeting's memos and documents, memo tags, user commands and
dictation/meeting templates, and registers the desktop as a device that the
phone can disconnect.

Fixes shipped defects: the first pull after sign-in fetched nothing, only
the first meeting's children were pushed, team meetings leaked into the
personal database and lost team_id on re-push, and Realtime never connected
because Electron's Node 20 has no global WebSocket (ws is now the transport).
Anonymous local-mode records are imported into the first account that signs
in. The settings sync section is translated and shows pending/rejected
changes; synced screens reload on app:dataChanged.
2026-09-27 14:04:49 +09:00

30 lines
899 B
TypeScript

// tests/helpers/createTestDb.ts
// in-memory SQLite + drizzle-orm 스키마 적용 (src/main/db/index.ts applySchema 그대로)
import Database from 'better-sqlite3'
import { drizzle, type BetterSQLite3Database } from 'drizzle-orm/better-sqlite3'
import * as schema from '../../src/main/db/schema'
import { applySchema } from '../../src/main/db'
/**
* 테스트용 in-memory SQLite DB를 생성한다.
* 각 테스트에서 독립적인 DB를 사용할 수 있다.
*/
export function createTestDb(): {
db: BetterSQLite3Database<typeof schema>
sqlite: Database.Database
close: () => void
} {
const sqlite = new Database(':memory:')
// 운영과 같은 스키마 정본을 쓴다 — 손으로 복제한 DDL은 컬럼 추가 때마다 어긋났다.
applySchema(sqlite)
const db = drizzle(sqlite, { schema })
return {
db,
sqlite,
close: () => sqlite.close(),
}
}