core: move index migrations to main database migrations

this is better design wise as we won't have to keep checking if the
indices have been migrated or not. We'll just check the database version
and do the appropriate migrations based on that.
This commit is contained in:
Abdullah Atta
2022-10-17 22:36:53 +05:00
parent 1a589b0955
commit 577d50b512
7 changed files with 171 additions and 74 deletions

View File

@@ -154,32 +154,39 @@ export default class Backup {
"This backup was made from a newer version of Notesnook. Cannot migrate."
);
// we have to reindex to make sure we handle all the items
// properly.
reindex(data);
const collections = [
{
index: data["attachments"],
index: () => data["attachments"],
dbCollection: this._db.attachments
},
{
index: data["notebooks"],
index: () => data["notebooks"],
dbCollection: this._db.notebooks
},
{
index: data["content"],
index: () => data["content"],
dbCollection: this._db.content
},
{
index: data["shortcuts"],
index: () => data["shortcuts"],
dbCollection: this._db.shortcuts
},
{
index: data["notes"],
index: () => data["notehistory"],
dbCollection: this._db.noteHistory,
type: "notehistory"
},
{
index: () => data["sessioncontent"],
dbCollection: this._db.noteHistory.sessionContent,
type: "sessioncontent"
},
{
index: () => data["notes"],
dbCollection: this._db.notes
},
{
index: ["settings"],
index: () => ["settings"],
dbCollection: this._db.settings,
type: "settings"
}