-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_sync.js
40 lines (32 loc) · 901 Bytes
/
db_sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var orm = require("orm");
var mysql = require("mysql");
var Sync = require("sql-ddl-sync").Sync;
//var mysqlUrl = "mysql://username:password@host/database";
var mysqlUrl = "mysql://b71bcfbc8362a6:98d136af@us-cdbr-east-05.cleardb.net/" +
"heroku_504ba427da8966b?reconnect=true";
orm.connect(mysqlUrl, function (err, db) {
//http://nodejsreactions.tumblr.com/post/64395522362/if-err-throw-err
if (err) throw err;
var driver = db.driver;
var sync = new Sync({
dialect: "mysql",
driver: driver,
debug: function (text) {
console.log("> %s", text);
}
});
sync.defineCollection("person", {
firstName: String,
lastName: String,
age: Number
});
sync.sync(function (err) {
if (err) {
console.log("> Sync Error");
console.log(err);
} else {
console.log("> Sync Done");
}
process.exit(0);
});
});