masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
227 stars 67 forks source link

Update schema from code causes mismatch with schema model file. #209

Closed giorgosnty closed 4 years ago

giorgosnty commented 4 years ago

So, the case is you have a project and you want to update the schema of a table. You can do it easily with an update(plain cql or using express-cassandra).

The schema before looks like this in 'models/testModel'.

testModel.js

module.exports = {
    fields:{
        username: "text",
        name: "text",
        age:"int",
    },
    key: ["username"]
}

And the file where all the db functions are stored:

db.js

const testModel =  require('./models/testModel');

...

this.testModel = this.models.loadSchema('testModel', testModel);
      this.testModel.syncDB((err, result) => {
        if (err) throw err;
        console.log('result', result)
      });

    }

But if I add a property e.g. weight It gets updated correctly and result true is appearing in the console. The issue is that now there is a mismatch between the testModel and the actual schema so the next time the app restarts it produces an error.

Is there any workaround for this issue?

masumsoft commented 4 years ago

updating schema dynamically is not supported by express-cassandra.