After studying the Dexie documentation on versioning, I am unclear about some aspects of versioning using Dexie 3.0.1.
Suppose I have table1
and table2
with only id
as an index on each for version 1 of my db:
db.version(1).stores({table1: "++id", table2: "++id"});
For version 2 of my db, I add shoeSize
as an index of table1
:
db.version(2).stores({table1: "++id,shoeSize"});
For version 3 of my db, I add dateOfBirth
as an index of table2
.
db.version(3).stores({table2: "++id,dateOfBirth"});
If I understand correctly, for Dexie 3.0, my final code should only have the last change to stores
: db.version(3).stores({table2: "++id,dateOfBirth"});
. It will NOT have version 2: db.version(2).stores({table1: "++id,shoeSize"});
.
So, if a user installs version 1 of my app, then upgrades directly to version 3, how will his table1
get updated to have the shoeSize
index? How should I handle versioning multiple tables with Dexie 3.0?
According to the current documentation:
If a previous version is installed, Dexie will filter out the diff between each version and add/remove stores and indexes sequentially.
=> you specify all the version changes and Dexie will execute each necessary ones. In your example, a user having a DB at v1 and downloading the v3 code, will have Dexie running both lines:
db.version(3).stores({table2: "++id,dateOfBirth"});
db.version(2).stores({table1: "++id,shoeSize"});