diff --git a/packages/core/api/index.js b/packages/core/api/index.js index f52e14951..091cce0f0 100644 --- a/packages/core/api/index.js +++ b/packages/core/api/index.js @@ -26,6 +26,7 @@ import NoteHistory from "../collections/note-history"; import MFAManager from "./mfa-manager"; import EventManager from "../utils/event-manager"; import Pricing from "./pricing"; +import { logger } from "../logger"; /** * @type {EventSource} @@ -125,9 +126,11 @@ class Database { await this.settings.init(); await this.outbox.init(); await this.user.init(); - await this.migrations.init(); - await this.migrations.migrate(); + + if (this.migrations.required()) { + logger.warn("Database migration is required."); + } } disconnectSSE() { diff --git a/packages/core/api/migrations.js b/packages/core/api/migrations.js index 3eab5c194..47370d2ba 100644 --- a/packages/core/api/migrations.js +++ b/packages/core/api/migrations.js @@ -1,4 +1,4 @@ -import { CURRENT_DATABASE_VERSION, EVENTS } from "../common"; +import { CURRENT_DATABASE_VERSION } from "../common"; import Migrator from "../database/migrator"; class Migrations { @@ -18,14 +18,13 @@ class Migrations { this._db.storage.write("v", this.dbVersion); } - async migrate() { - if (this.dbVersion >= CURRENT_DATABASE_VERSION || this._isMigrating) return; + required() { + return this.dbVersion < CURRENT_DATABASE_VERSION; + } + async migrate() { + if (!this.required() || this._isMigrating) return; this._isMigrating = true; - this._db.eventManager.publish(EVENTS.databaseMigrating, { - from: this.dbVersion, - to: CURRENT_DATABASE_VERSION, - }); await this._db.notes.init(); const content = await this._db.content.all(); @@ -64,11 +63,7 @@ class Migrations { ]; await this._migrator.migrate(collections, (item) => item, this.dbVersion); await this._db.storage.write("v", CURRENT_DATABASE_VERSION); - - setTimeout(() => { - this._db.eventManager.publish(EVENTS.databaseMigrated); - this.dbVersion = CURRENT_DATABASE_VERSION; - }, 5000); + this.dbVersion = CURRENT_DATABASE_VERSION; } } export default Migrations; diff --git a/packages/core/common.js b/packages/core/common.js index dff338dee..c4155b7ae 100644 --- a/packages/core/common.js +++ b/packages/core/common.js @@ -51,8 +51,6 @@ export const EVENTS = { databaseSyncRequested: "db:syncRequested", syncProgress: "sync:progress", syncCompleted: "sync:completed", - databaseMigrated: "db:migrated", - databaseMigrating: "db:migrating", databaseUpdated: "db:updated", databaseCollectionInitiated: "db:collectionInitiated", appRefreshRequested: "app:refreshRequested",