v12.0.0 - initial commit
This commit is contained in:
commit
e2c49ea43c
1145 changed files with 97211 additions and 0 deletions
35
packages/server/tools/migrate-env.js
Normal file
35
packages/server/tools/migrate-env.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
const setEnvVariable = require('./set-env-var')
|
||||
|
||||
const ENV_PATH =
|
||||
process.env.NODE_ENV === 'production'
|
||||
? path.resolve('/etc', 'lamassu', '.env')
|
||||
: path.resolve(__dirname, '../.env')
|
||||
const BACKUP_TIMESTAMP = Date.now()
|
||||
const BACKUP_PATH = `${ENV_PATH}-${BACKUP_TIMESTAMP}`
|
||||
|
||||
const migrateEnv = newVars => {
|
||||
try {
|
||||
fs.copyFileSync(ENV_PATH, BACKUP_PATH)
|
||||
_.forEach(it => {
|
||||
setEnvVariable(it[0], it[1], { ENV_PATH })
|
||||
}, newVars)
|
||||
fs.unlinkSync(BACKUP_PATH)
|
||||
console.log('Environment migration successful')
|
||||
} catch (e) {
|
||||
// Rollback the migration and restore the backup file
|
||||
if (fs.existsSync(BACKUP_PATH)) {
|
||||
console.log('Rolling back the environment migration...')
|
||||
fs.copyFileSync(BACKUP_PATH, ENV_PATH)
|
||||
fs.unlinkSync(BACKUP_PATH)
|
||||
console.log('Rollback finished')
|
||||
}
|
||||
console.log('Environment migration failed')
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = migrateEnv
|
||||
Loading…
Add table
Add a link
Reference in a new issue