-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Migration after database model update #39
Comments
Hello Anton, No worries, the best thing to do in this case is just set an ID in your database config:
If you don't provide an ID one is generated from a hash of the data model, which is why you're getting a new database when the datamodel changes. However, if you set an ID to the database it'll always attach to the same backend database (IndxedDB or whatever you're using) regardless of data model changes. Hope that helps! |
Aha! It does. Thank you. This solves my problems. So then, I can track the db version in a table, and have migrator functions that trigger based on that value. But I won't be able to use two different models at the same time... If I try to |
No, data sanitization happens only on The major exception to this is the secondary indexes. If you add/remove secondary indexes to the data model you'll need to rebuild them after the data model change like this: nSQL().extend("rebuild_idx", "tableToRebuild").then... |
This is awesome. This should be enough of a guide for anyone trying to migrate their data. Once I get around migrations in my own code, and try them out on my own skin, could I add to the nano-sql docs? |
@plentylife Did you ever get around to adding this to the docs? It would be very valuable as I couldn’t currently find any information on migrations whatsoever. Also, it would be a great feature to have migration/versioning support baked in (e.g., like in Dexie – which exposes |
Hi @aral, No, I never did add it to the docs. I never got around writing the code to migrate data yet. As far as I understand, it's up to us to write our own migration code (for now), which shouldn't be that much of a problem. I mean realistically speaking, there's always migration code that needs to be written by hand. The way I was going to go about it is:
|
Hi Scott,
I'm bothering you again :)
This is an experience of every project out there. You make a database model. Then you change it.
In the case of nano-sql and indexeddb, it creates a new database.
The question is, how do we get the old data into the new database?
I found this doc, https://docs.nanosql.io/adapters/transfer, but it doesn't exactly answer my question.
Best wishes,
Anton
PS. For me this is a real problem, but can be simplified to this: how do I extract one table from the old database and put it in the new database, if the table model is exactly the same?
The text was updated successfully, but these errors were encountered: