(db: DatabaseAdapter)
| 18 | * 读取数据库的 schema 版本 |
| 19 | */ |
| 20 | export function getSchemaVersion(db: DatabaseAdapter): number { |
| 21 | try { |
| 22 | const tableInfo = db.pragma('table_info(meta)') as Array<{ name: string }> |
| 23 | const hasVersionColumn = tableInfo.some((col) => col.name === 'schema_version') |
| 24 | if (!hasVersionColumn) return 0 |
| 25 | |
| 26 | const result = db.prepare('SELECT schema_version FROM meta LIMIT 1').get() as |
| 27 | | { schema_version: number | null } |
| 28 | | undefined |
| 29 | return result?.schema_version ?? 0 |
| 30 | } catch { |
| 31 | return 0 |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * 设置数据库的 schema 版本 |
no test coverage detected