forked from akai/readest
feat(database): add platform-agnostic schema migration system (#3485)
This commit is contained in:
@@ -43,6 +43,7 @@ import { copyFiles } from '@/utils/files';
|
||||
|
||||
import { BaseAppService } from './appService';
|
||||
import { DatabaseOpts, DatabaseService } from '@/types/database';
|
||||
import { SchemaType } from '@/services/database/migrate';
|
||||
import {
|
||||
DATA_SUBDIR,
|
||||
LOCAL_BOOKS_SUBDIR,
|
||||
@@ -565,10 +566,19 @@ export class NativeAppService extends BaseAppService {
|
||||
return await ask(message);
|
||||
}
|
||||
|
||||
async openDatabase(path: string, base: BaseDir, opts?: DatabaseOpts): Promise<DatabaseService> {
|
||||
async openDatabase(
|
||||
schema: SchemaType,
|
||||
path: string,
|
||||
base: BaseDir,
|
||||
opts?: DatabaseOpts,
|
||||
): Promise<DatabaseService> {
|
||||
const fullPath = await this.resolveFilePath(path, base);
|
||||
const { NativeDatabaseService } = await import('./database/nativeDatabaseService');
|
||||
return NativeDatabaseService.open(`sqlite:${fullPath}`, opts);
|
||||
const db = await NativeDatabaseService.open(`sqlite:${fullPath}`, opts);
|
||||
const { migrate } = await import('./database/migrate');
|
||||
const { getMigrations } = await import('./database/migrations');
|
||||
await migrate(db, getMigrations(schema));
|
||||
return db;
|
||||
}
|
||||
|
||||
async migrate20251029() {
|
||||
|
||||
Reference in New Issue
Block a user