Merge pull request #1860 from RafaelTaranto/chore/verify-postgres-version-before-migrate
LAM-1405 chore: verify postgres version before migrate
This commit is contained in:
commit
5b7f028636
1 changed files with 26 additions and 5 deletions
|
|
@ -13,11 +13,32 @@ const createMigration = `CREATE TABLE IF NOT EXISTS migrations (
|
||||||
// no need to log the migration process
|
// no need to log the migration process
|
||||||
process.env.SKIP_SERVER_LOGS = true
|
process.env.SKIP_SERVER_LOGS = true
|
||||||
|
|
||||||
db.none(createMigration)
|
function checkPostgresVersion () {
|
||||||
.then(() => migrate.run())
|
return db.one('SHOW server_version;')
|
||||||
.then(() => {
|
.then(result => {
|
||||||
console.log('DB Migration succeeded.')
|
console.log(result)
|
||||||
process.exit(0)
|
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 => {
|
.catch(err => {
|
||||||
console.error('DB Migration failed: %s', err)
|
console.error('DB Migration failed: %s', err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue