Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Last active March 20, 2020 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianjmiller/11297772 to your computer and use it in GitHub Desktop.
Save brianjmiller/11297772 to your computer and use it in GitHub Desktop.
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