Comments (6)
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?
from nano-sql.
Hello Anton,
No worries, the best thing to do in this case is just set an ID in your database config:
nSQL()
.config({
id: "my_db"
})...
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!
from nano-sql.
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 select
old data from the database, using the new model, and the data types are incompatible, will nano-sql throw an error?
from nano-sql.
If I try to select old data from the database, using the new model, and the data types are incompatible, will nano-sql throw an error?
No, data sanitization happens only on upsert
quries, not select
queries. Meaning you could change the data model from anything to anything else and as long as the primary key column has remained the same everything would work just fine.
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...
from nano-sql.
@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 version()
and upgrade()
methods – http://dexie.org/docs/Tutorial/Understanding-the-basics#migrate-data.)
from nano-sql.
Hi @aral,
No, I never did add it to the docs. I never got around writing the code to migrate data yet.
So I haven't battle tested my own project with it 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:
- Keep the version info in the database id
- Make a function that checks db id, and triggers on it
- Create a new datbase
- That function would run queries on copying data from the old to the new database
- Done
from nano-sql.
Related Issues (20)
- NODERAWFS error for some adapters
- Cannot insert a record with an id of 0 (zero) if the id field is a primary key
- Index does not be built correctly.
- [HELP] Increment value HOT 1
- TTL feature always status time -1
- Incorrect behavior with joins and filters
- jsLoad not respect unique index
- Why can column names not begin with an underscore? HOT 1
- Bug with select from HOT 2
- foreignKey: onUpdate support HOT 1
- copy database
- nSQL: Can't do a query before the database is connected! HOT 1
- Can't query tables after restart, log parsing error HOT 1
- [Meta] Is this project still maintained? HOT 3
- LOG file "backs up" every change to a row HOT 1
- Selection of date types with undefined values
- Adding support for WebExtensions
- Support for Capacitor?
- Remove WebSQL usage and/or method calls from this repository
- Does nanoSQL work correctly on Safari s it does on Chrome?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nano-sql.