MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / runMigrations

Function runMigrations

packages/core/src/schema/migrations.ts:64–83  ·  view source on GitHub ↗
(db: DatabaseAdapter, migrationsList: Migration[], forceRepair = false)

Source from the content-addressed store, hash-verified

62 * @returns 是否执行了迁移
63 */
64export function runMigrations(db: DatabaseAdapter, migrationsList: Migration[], forceRepair = false): boolean {
65 const currentVersion = getSchemaVersion(db)
66
67 if (!forceRepair && currentVersion >= (migrationsList.at(-1)?.version ?? 0)) {
68 return false
69 }
70
71 const pending = forceRepair ? migrationsList : migrationsList.filter((m) => m.version > currentVersion)
72
73 if (pending.length === 0) return false
74
75 db.transaction(() => {
76 for (const migration of pending) {
77 migration.up(db)
78 setSchemaVersion(db, migration.version)
79 }
80 })
81
82 return true
83}

Callers 1

migrateDatabaseFunction · 0.90

Calls 4

getSchemaVersionFunction · 0.85
setSchemaVersionFunction · 0.85
upMethod · 0.80
transactionMethod · 0.65

Tested by

no test coverage detected