You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created a class for Dexie Database Management like
//DBManager.js (simplified version)
class DBManager{
constructor(){}
createConnection(){
this.db = new Dexie('myDB');
let ver = localStorage.getItem('dbVersion') ?? 1;
let schema = {tblA : '++id, cid', tblB : '++id, uid'};
this.db.version(ver).stores(schema); //Problems seems here as it is always using same schema even for new version
return this.db;
}
}
}
On every page load, I call like this
let dbManager = new DBManager();
let db = dbManager.createConnection();
and then use this db variable for database operations.
But when I refresh page, it does not have my new table tblC but only tblA and tblB. It's may be as I pointed because it always uses the same schema even with newer versions. Or am I missing something else?
My Questions are
Do I need to store new Schema as well and use new Schema with new version? like
localStorage.setItem('dbSchema', JSON.stringify(old + new schema)); //Add this new Schema with new version in
this.db.version(localStorage.getItem('dbVersion') ?? 1).stores(JSON.parse(localStorage.getItem('dbSchema')));
Will my new version (2) have all my new and old tables along with data or I will have to migrate data from old version to new version of database everytime I upgrade schema?
What if I do not want to migrate because I may be needing to upgrade schema every now and then.
Does upgrading schema of a table also reindex previous fields as well or just new one?
When upgrading a schema, do we need to tell schema for previous tables as well or just new tables?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have created a class for Dexie Database Management like
On every page load, I call like this
and then use this db variable for database operations.
Now I upgrade schema and version of database like
But when I refresh page, it does not have my new table tblC but only tblA and tblB. It's may be as I pointed because it always uses the same schema even with newer versions. Or am I missing something else?
My Questions are
Do I need to store new Schema as well and use new Schema with new version? like
Will my new version (2) have all my new and old tables along with data or I will have to migrate data from old version to new version of database everytime I upgrade schema?
What if I do not want to migrate because I may be needing to upgrade schema every now and then.
Does upgrading schema of a table also reindex previous fields as well or just new one?
When upgrading a schema, do we need to tell schema for previous tables as well or just new tables?
Beta Was this translation helpful? Give feedback.
All reactions