MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / openDatabaseWithMigration

Function openDatabaseWithMigration

apps/desktop/main/database/core.ts:94–111  ·  view source on GitHub ↗
(
  sessionId: string,
  forceRepair = false,
  runtime?: RuntimeIdentity
)

Source from the content-addressed store, hash-verified

92 * @param forceRepair 是否强制修复(即使版本号已是最新也重新执行迁移脚本)
93 */
94export function openDatabaseWithMigration(
95 sessionId: string,
96 forceRepair = false,
97 runtime?: RuntimeIdentity
98): Database.Database | null {
99 const dbPath = getDbPath(sessionId)
100 if (!fs.existsSync(dbPath)) {
101 return null
102 }
103
104 const db = new Database(dbPath)
105 db.pragma('journal_mode = WAL')
106
107 // 执行迁移
108 migrateDatabase(db, forceRepair, { pathProvider: getPathProvider(), runtime })
109
110 return db
111}
112
113/**
114 * 导入解析后的数据到数据库

Callers 2

updateSessionOwnerIdFunction · 0.85
migrateAllDatabasesFunction · 0.85

Calls 4

migrateDatabaseFunction · 0.90
getPathProviderFunction · 0.90
getDbPathFunction · 0.70
pragmaMethod · 0.65

Tested by

no test coverage detected