masumsoft/express-cassandra

Update schema from code causes mismatch with schema model file.

giorgosnty opened this issue · 1 comments

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?

updating schema dynamically is not supported by express-cassandra.