I'm using node-orm to try to setup my database. Here is the model code.
db = orm.connect("mysql", client, (success, db) ->
Strain = db.define("strain",
name:
type: "string"
validations: [ orm.validators.unique() ]
old_body:
type: "string"
body:
type: "string"
created_at:
type: "date"
update_at:
type: "date"
)
Strain.sync()
)
I changed the /orm/lib/databases/mysql.js file to console.log the returned Sync info.
this._client.query(_query, function (err, info) {
console.log(err);
console.log(info);
console.log("collection synced");
});
The first time Strain.sync() runs, this is the output.
null
{ affectedRows: 0,
insertId: 0,
serverStatus: 2,
warningCount: 0,
message: '',
setMaxListeners: [Function],
emit: [Function],
addListener: [Function],
on: [Function],
once: [Function],
removeListener: [Function],
removeAllListeners: [Function],
listeners: [Function] }
collection synced
Now the table is created as it should be. When I restart the server and run Strain.sync() again, this is the output:
null
{ affectedRows: 0,
insertId: 0,
serverStatus: 2,
warningCount: 1,
message: '',
setMaxListeners: [Function],
emit: [Function],
addListener: [Function],
on: [Function],
once: [Function],
removeListener: [Function],
removeAllListeners: [Function],
listeners: [Function] }
collection synced
The warning count jumped to "1", but err is null, and message is empty.
I need to figure out how I can change the model and add a new property, like "deleted_at", and update the table WITHOUT losing data. I know I can do Strain.sync( force: true ), but that will drop the table then re-create it. I'm just looking to update the table, similar to DataMapper's auto_upgrade function.
Is there any way to do this with node-orm, or any ORM that works with nodejs?
Pretty sure the current version of sync() only creates tables, does not update.
Note: sync() only creates tables at the moment; table modifications will be added in an upcoming version.
https://github.com/dresende/node-orm#creating-the-model-on-the-database