I have to create user defined tables in waterline though custom query method(.query()).
custom.con.query("CREATE TABLE "+req.body.table_name+",function(err,model){});
After that i have to create coloumns in this table again through custom query.
custom.con.query("ALTER TABLE "+req.body.table_name+" ADD "+req.body.coloumn_name,function(err,model){});
Problem is once table is created and it's coloumns also created.but when i restart server coloumns in table vanish.
In other waterline models i can handle this problem by setting value of migrate:"safe".
Is there any way to set such configuration in custom tables.???
user786, it seems that you have your default migrate
setting set to 'alter'
or 'drop'
. You can change this by adding a defaults
object to your waterline initialisation, example:
var config = {
// adapters
// models
// etc...
defaults: {
// will apply to any model that doesn't have a 'migrate' definition
migrate: 'safe'
}
};
waterline.initialize(config, function(err, models) {
console.log("waterline initialised.");
});
Code example in waterline examples.
The non-destructive options are 'safe'
and 'create'
, more details in the adapter specification docs and in sails model settings.