Giter Club home page Giter Club logo

Comments (6)

plentylife avatar plentylife commented on May 18, 2024 1

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.

only-cliches avatar only-cliches commented on May 18, 2024

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.

plentylife avatar plentylife commented on May 18, 2024

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.

only-cliches avatar only-cliches commented on May 18, 2024

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.

aral avatar aral commented on May 18, 2024

@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.

plentylife avatar plentylife commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.