Fix v4 migration when no existing .env

This commit is contained in:
Chrystian Huot 2020-05-15 16:26:31 -04:00
parent 020d559667
commit 6e604706b8

View file

@ -37,7 +37,9 @@ module.exports = {
const envFile = path.resolve(__dirname, '../../../.env');
const env = fs.existsSync(envFile) ? dotenv.parse(fs.readFileSync(envFile)) : {};
const envFileExists = fs.existsSync(envFile);
const env = envFileExists ? dotenv.parse(fs.readFileSync(envFile)) : {};
const oldSystem = sequelize.define('rdioScannerSystem', {
aliases: {
@ -76,6 +78,7 @@ module.exports = {
let systems;
if (envFileExists) {
try {
systems = await oldSystem.findAll({ order: [['system', 'ASC']] });
@ -99,6 +102,10 @@ module.exports = {
systems = getExampleSystems();
}
} else {
systems = getExampleSystems();
}
const config = {
nodejs: {
env: env.NODE_ENV || 'production',
@ -128,8 +135,10 @@ module.exports = {
fs.writeFileSync(configFile, JSON.stringify(config, null, 4));
if (fs.existsSync(envFile)) {
fs.unlinkSync(envFile);
}
}
const transaction = await sequelize.transaction();