-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate.js
30 lines (27 loc) · 828 Bytes
/
migrate.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
"use strict"
var knex = require("knex")({
client: "pg",
connection: process.env.DATABASE_URL,
});
var fs = require('fs');
var accounts = JSON.parse(fs.readFileSync("./public/accounts.json", "utf8"));
console.log("Starting Database Migration...")
knex.schema.hasTable("accounts").then(function(exists) {
if (!exists) {
return knex.schema.createTable("accounts", function(t) {
t.increments("id").primary();
t.string("name", 100);
t.text("description");
}).then(() => {
return knex("accounts").insert(accounts);
});
}
console.log("Accounts table already exists, skipping migration.");
}).then(() => {
console.log("Release stage finished successfully.");
process.exit();
}).catch(err => {
console.log("Release stage failed. Maybe no database was provisioned?");
console.log(err);
process.exit(1);
});