Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bookshelf migration
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();
}
);
};
module.exports = function () {
this.appConfig = {
dsn: {
host: "localhost",
port: 5432,
db: "...",
username: "...",
password: "...",
dialect: "postgres"
}
};
};
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