v12.0.0 - initial commit
This commit is contained in:
commit
e2c49ea43c
1145 changed files with 97211 additions and 0 deletions
46
packages/server/bin/lamassu-migrate
Executable file
46
packages/server/bin/lamassu-migrate
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env node
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
require('../lib/environment-helper')
|
||||
const db = require('../lib/db')
|
||||
const migrate = require('../lib/migrate')
|
||||
|
||||
const createMigration = `CREATE TABLE IF NOT EXISTS migrations (
|
||||
id serial PRIMARY KEY,
|
||||
data json NOT NULL
|
||||
)`
|
||||
|
||||
// no need to log the migration process
|
||||
process.env.SKIP_SERVER_LOGS = true
|
||||
|
||||
function checkPostgresVersion () {
|
||||
return db.one('SHOW server_version;')
|
||||
.then(result => {
|
||||
console.log(result)
|
||||
const versionString = result.server_version
|
||||
const match = versionString.match(/(\d+)\.(\d+)/i)
|
||||
if (!match) {
|
||||
throw new Error(`Could not parse PostgreSQL version: ${versionString}`)
|
||||
}
|
||||
return parseInt(match[1], 10)
|
||||
})
|
||||
}
|
||||
|
||||
checkPostgresVersion()
|
||||
.then(majorVersion => {
|
||||
if (majorVersion < 12) {
|
||||
console.error('PostgreSQL version must be 12 or higher. Current version:', majorVersion)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
return db.none(createMigration)
|
||||
.then(() => migrate.run())
|
||||
.then(() => {
|
||||
console.log('DB Migration succeeded.')
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('DB Migration failed: %s', err)
|
||||
process.exit(1)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue