Closed giorgosnty closed 4 years ago
express-cassandra migration system checks for model changes when models.setDirectory
is called. You could also use your_model_instance.syncDB()
to explicitly migrate a particular model.
If however NODE_ENV==production
then models.setDirectory
never does the migrations automatically. This is a design decision to reduce the chance of accidental deletion of production data.
Ideally you should execute migrations manually in a production environment or use syncDB()
in your own scripts in the deployment stage of the production app.
However if you really want to use the automatic migration features in production, then you may actually set NODE_ENV to something other than production before doing the migrations and keep your fingers crossed! Though I'll highly discourage against enabling automatic migrations in production as this may lead to accidental deletion of data.
Hi, thanks a lot for the answer.
I am using sync db like that inside ExpressCassandra.createClient() and if I do changes it is working and prints 'result true'.
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)
});
}
The problem is when restarting that there is the difference I mentioned above.
I think this issue should not close yet.
Model looks like this:
And when updating it and add property e.g. weight it is ok until restarting the app. Then, it produces an error because the schema does not match the model.
It's ok in development, but what's the solution in order to be able use it in production?