feat(database): add platform-agnostic schema migration system (#3485)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { FileSystem, BaseDir, AppPlatform, ResolvedPath, FileItem } from '@/types/system';
|
||||
import { DatabaseOpts, DatabaseService } from '@/types/database';
|
||||
import { SchemaType } from '@/services/database/migrate';
|
||||
import { getOSPlatform, isValidURL } from '@/utils/misc';
|
||||
import { RemoteFile } from '@/utils/file';
|
||||
import { isPWA } from './environment';
|
||||
@@ -349,9 +350,18 @@ export class WebAppService extends BaseAppService {
|
||||
return window.confirm(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 { WebDatabaseService } = await import('./database/webDatabaseService');
|
||||
return WebDatabaseService.open(fullPath, opts);
|
||||
const db = await WebDatabaseService.open(fullPath, opts);
|
||||
const { migrate } = await import('./database/migrate');
|
||||
const { getMigrations } = await import('./database/migrations');
|
||||
await migrate(db, getMigrations(schema));
|
||||
return db;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user