mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
core: send db name with migration events
This commit is contained in:
@@ -253,7 +253,8 @@ class Database {
|
||||
|
||||
await initializeDatabase(
|
||||
this.sql().withTables(),
|
||||
new NNMigrationProvider()
|
||||
new NNMigrationProvider(),
|
||||
"notesnook"
|
||||
);
|
||||
await this.onInit(this.sql() as unknown as Kysely<RawDatabaseSchema>);
|
||||
await this.initCollections();
|
||||
|
||||
@@ -302,7 +302,8 @@ async function setupDatabase<Schema>(
|
||||
|
||||
export async function initializeDatabase<Schema>(
|
||||
db: Kysely<Schema>,
|
||||
migrationProvider: MigrationProvider
|
||||
migrationProvider: MigrationProvider,
|
||||
name: string
|
||||
) {
|
||||
try {
|
||||
const migrator = new Migrator({
|
||||
@@ -314,9 +315,9 @@ export async function initializeDatabase<Schema>(
|
||||
.then((m) => m.some((m) => !m.executedAt));
|
||||
if (!needsMigration) return db;
|
||||
|
||||
EV.publish(EVENTS.migrationStarted);
|
||||
EV.publish(EVENTS.migrationStarted, name);
|
||||
const { error, results } = await migrator.migrateToLatest();
|
||||
EV.publish(EVENTS.migrationFinished);
|
||||
EV.publish(EVENTS.migrationFinished, name);
|
||||
|
||||
if (error)
|
||||
throw error instanceof Error ? error : new Error(JSON.stringify(error));
|
||||
@@ -364,7 +365,7 @@ export async function createDatabase<Schema>(
|
||||
dialect: options.dialect(name, async () => {
|
||||
await db.connection().execute(async (db) => {
|
||||
await setupDatabase(db, options);
|
||||
await initializeDatabase(db, options.migrationProvider);
|
||||
await initializeDatabase(db, options.migrationProvider, name);
|
||||
if (options.onInit) await options.onInit(db);
|
||||
});
|
||||
}),
|
||||
@@ -373,7 +374,7 @@ export async function createDatabase<Schema>(
|
||||
if (!options.skipInitialization)
|
||||
await db.connection().execute(async (db) => {
|
||||
await setupDatabase(db, options);
|
||||
await initializeDatabase(db, options.migrationProvider);
|
||||
await initializeDatabase(db, options.migrationProvider, name);
|
||||
if (options.onInit) await options.onInit(db);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user