Closed kwlayman closed 4 years ago
Thanks @kwlayman
Answer to your issues is -
yes data will be lost, so better is to leave old table , create another table with new schema and then import data from old table to new table.
No, IndexedDb is nosql database, so there is no relationship between tables. You will have to take care this manually. Basically insert each data manually & verify with second table & if there is any issue remove inserted data , you can use transaction for this.
You can't update a table schema without recreating it. This is IndexedDb limitation.
Thanks for the quick response.
Regarding #2 my question relates to how to keep from recreating primary keys so as to keep from losing the existing relationships with the foreign keys in related tables. So specifically Is there a way to temporarily disable autoincrement on a Primary Key?
I should have said disable autoincrement for the purpose of importing existing records with Primary Keys, and then re-enabling autoincrement for normal insertions?
you can use skipDataCheck
in insert query.
Regarding #1, how can I create a new table in the same schema w/o losing the data in the existing tables? I'm obviously missing something here as I understand you to say I can't add a table to an existing schema w/o recreating entire schema, so how can I then copy the data from the old table when it has been replaced with the new schema?
Regarding #1 you can disregard my last comment, I think I understand how to do it, thx!
Still seems fraught with danger though as the data only exists in memory during the process?
Maybe better to create new database entirely? JsStore can maintain open connections to multiple databases?
no it wont be in memory - when you create another table your old table data persists. So its just you fetch data from one table & insert to another.
e.g - let's say you have a table customer
& you are upgrading your schema so you created anoher table customerV2
, now when db is created you move data from customer to customerV2. Now customerV2 is your active table.
Yes its simple & clean to create another database but you will have to make sure you are not having issues with indexedDb quota.
Yes jsstore can maintain multiple database connection but only when you are using web worker. Without webworker there is a context mixup issue.
When I create a new table the old tables disappear in JsStore even though they are still present in IndexedDB according to Google developer tools. They do not show up using getDbSchema, only the new table does.
Ok I figured out what I was doing wrong, I'll update this with my mistakes.
@kwlayman here is an example of changing db schema - https://github.com/ujjwalguptaofficial/jsstore-examples/tree/master/change-db-schema
Trying your library, so far is awesome, nice work!
I do have an issues with versioning though. I'm looking at your example of how to change a table by doing a select all, then changing schema, then importing all. When I try this I have a couple of issues/questions:
What to do if insert fails because old data is not 100% compatible with new schema? It seems in my tests that unless something like a temp table is manually created and used the data will be lost.
What about the Autoincremented Primary Key that is used in other tables as a FK? Is there a way to handle this?
I don't seem to be able to add a table to an existing schema w/o recreating entire schema with new table?