Forked from brianjmiller/20130808024530000-table-time_zones.js
Created
September 2, 2016 04:48
-
-
Save gerzhan/b633bf229ebf6613497edc2f5f8c6f4a to your computer and use it in GitHub Desktop.
Bookshelf migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dbh = require("../migrations"), | |
relationName = "time_zones"; | |
exports.up = function (next) { | |
dbh.schema.createTable( | |
relationName, | |
function (table) { | |
table.string("code", 50).primary(); | |
table.timestamps(); | |
table.integer("utc_offset").notNullable(); | |
table.boolean("is_visible").notNullable(); | |
} | |
).then( | |
function () { | |
return dbh(relationName).insert( | |
[ | |
{ | |
code: "US/Eastern", | |
created_at: "NOW()", | |
updated_at: "NOW()", | |
utc_offset: -5, | |
is_visible: true | |
} | |
] | |
); | |
} | |
).then( | |
function () { | |
next(); | |
} | |
).otherwise( | |
function (err) { | |
console.error("Error occurred:", err); | |
next(err); | |
} | |
); | |
}; | |
exports.down = function (next) { | |
dbh.schema.dropTableIfExists(relationName).then( | |
function () { | |
next(); | |
} | |
); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function () { | |
this.appConfig = { | |
dsn: { | |
host: "localhost", | |
port: 5432, | |
db: "...", | |
username: "...", | |
password: "...", | |
dialect: "postgres" | |
} | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Knex = require("knex"), | |
Config = require("./config/environments/development"), | |
config = (new Config).appConfig; | |
module.exports = Knex.initialize( | |
{ | |
client: "pg", | |
connection: { | |
host: config.dsn.host, | |
username: config.dsn.username, | |
password: config.dsn.password, | |
database: config.dsn.db, | |
charset: "utf8" | |
}, | |
debug: false | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment