(db: DatabaseAdapter, version: number)
| 36 | * 设置数据库的 schema 版本 |
| 37 | */ |
| 38 | export function setSchemaVersion(db: DatabaseAdapter, version: number): void { |
| 39 | const tableInfo = db.pragma('table_info(meta)') as Array<{ name: string }> |
| 40 | const hasVersionColumn = tableInfo.some((col) => col.name === 'schema_version') |
| 41 | |
| 42 | if (!hasVersionColumn) { |
| 43 | db.exec('ALTER TABLE meta ADD COLUMN schema_version INTEGER DEFAULT 0') |
| 44 | } |
| 45 | |
| 46 | db.prepare('UPDATE meta SET schema_version = ?').run(version) |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * 检查数据库是否需要迁移 |
no test coverage detected