forked from m3talsmith/pg-migrator
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdb-migrate.js
executable file
·51 lines (41 loc) · 1010 Bytes
/
db-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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
/* eslint-disable no-console, no-process-exit, no-process-env */
const migrate = require('db-migrator/lib/migrate')
const status = require('db-migrator/lib/status')
const dotenv = require('dotenv')
const path = require('path')
const env = process.argv[2] || 'local'
let envFile
switch (env) {
case 'staging':
case 'production':
case 'dev':
envFile = `.env-heroku-${env}`
break
default:
envFile = '.env'
}
dotenv.config({
path: path.join(__dirname, envFile),
})
if (!process.env.DATABASE_URL) {
console.error('DB connection string not defined.')
process.exit(1)
}
const DB_URL = `${process.env.DATABASE_URL}?ssl=true`
async function run() {
await status({
connectionString: DB_URL,
path: './migrations',
tableName: 'migrations',
})
await migrate({
connectionString: DB_URL,
path: './migrations',
tableName: 'migrations',
})
console.log(envFile, 'migrated')
}
run()
.then(() => process.exit(0))
.catch(() => process.exit(1))