fix(sync): bind sync engine to its user DB, scope instructions/templates per account, harden navigation

This commit is contained in:
Yun Chan 2026-09-28 00:53:42 +09:00
parent 1b8fe445f3
commit 9aa7302944
30 changed files with 2614 additions and 386 deletions

View file

@ -14,6 +14,7 @@ import path from 'path'
import * as schema from './schema'
import { getLogger } from '../services/LoggerService'
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
import { emitAccountScopeChanged, LOCAL_SCOPE_ID } from '../services/account-scope'
const logger = getLogger('database')
@ -29,7 +30,7 @@ const logger = getLogger('database')
* - `_local`: 무료 익명 사용자 entry point (킬러 피처 — 회원가입 0, 로컬 STT/LLM)
* - 실제 uuid: OAuth 로그인 후 클라우드 sync + premium 기능 (유료 SaaS 수익화)
*/
export const LOCAL_USER_ID = '_local'
export const LOCAL_USER_ID = LOCAL_SCOPE_ID
let currentUserId: string | null = null
let sqlite: Database.Database | null = null
@ -486,6 +487,8 @@ export function openForUser(userId: string): OpenForUserResult {
}
logger.info(`Database opened for user: ${userId}`)
// 계정 범위 저장소(명령·템플릿)도 이 사용자로 바꾼다 — 동기화 엔진이 만들어지기 전에 동기적으로 끝난다.
emitAccountScopeChanged(userId)
return { created: !existed, dbPath }
}
@ -650,6 +653,7 @@ export function bindTestDatabase(
): void {
db = testDb
currentUserId = userId
emitAccountScopeChanged(userId)
}
/** Vitest 전용: bindTestDatabase 해제. */