mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-25 11:13:19 +03:00
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
|
const { DataTypes } = require('sequelize');
|
||
|
const { INTEGER, DATE, STRING, TINYINT, FLOAT, TEXT } = DataTypes;
|
||
|
const { readFile, writeFile, copyFile } = require('fs/promises');
|
||
|
const Config = require('../../models/Config');
|
||
|
|
||
|
const up = async (query) => {
|
||
|
await copyFile('utils/init/initialConfig.json', 'data/config.json');
|
||
|
|
||
|
const initConfigFile = await readFile('data/config.json', 'utf-8');
|
||
|
const parsedNewConfig = JSON.parse(initConfigFile);
|
||
|
|
||
|
const existingConfig = await Config.findAll({ raw: true });
|
||
|
|
||
|
for (let pair of existingConfig) {
|
||
|
const { key, value, valueType } = pair;
|
||
|
|
||
|
let newValue = value;
|
||
|
|
||
|
if (valueType == 'number') {
|
||
|
newValue = parseFloat(value);
|
||
|
} else if (valueType == 'boolean') {
|
||
|
newValue = value == 1;
|
||
|
}
|
||
|
|
||
|
parsedNewConfig[key] = newValue;
|
||
|
}
|
||
|
|
||
|
const newConfig = JSON.stringify(parsedNewConfig);
|
||
|
await writeFile('data/config.json', newConfig);
|
||
|
|
||
|
// await query.dropTable('config');
|
||
|
};
|
||
|
|
||
|
const down = async (query) => {
|
||
|
// await query.dropTable('config');
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
up,
|
||
|
down,
|
||
|
};
|