refs #4823 Added floriday ascii

This commit is contained in:
Guillermo Bonet 2023-04-04 15:04:03 +02:00
parent 4b0ef20f63
commit cdd2fa269f
1 changed files with 54 additions and 24 deletions

View File

@ -1,19 +1,29 @@
import { Sequelize } from 'sequelize';
import dotenv from 'dotenv';
import colors from 'colors';
import ora from 'ora';
dotenv.config();
let sequelize = createConnection();
console.clear()
console.log(
`
`.green
)
console.log(`
`.green)
let sequelize = createConnection();
const conSpinner = ora('Creating the connection...').start();
try {
await sequelize.authenticate();
conSpinner.succeed();
} catch (err) {
conSpinner.fail();
myErr(err);
}
// Supply Line Models
import supplyLine from './supplyLine/supplyLine.js';
@ -150,24 +160,45 @@ models.tradeItem.belongsTo(models.supplier, {
targetKey: 'organizationId',
});
let action, force;
if (process.env.FORCE_SYNC === 'true') {
console.log('Forcing the models...');
await sequelize.sync({ force: true });
action = 'Forcing'
force = true
} else {
console.log('Altering the models...');
await sequelize.sync({ alter: true });
action = 'Altering'
force = false
}
if (process.env.SECRETS) {
await models.clientConfig.findOrCreate({
where: {
id: 1,
},
defaults: {
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
},
});
const modSpinner = ora(`${action} the models...`).start();
try {
await sequelize.sync({ force: force });
if (process.env.SECRETS) {
await models.clientConfig.findOrCreate({
where: {
id: 1,
},
defaults: {
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
},
});
}
modSpinner.succeed();
}
catch (err) {
modSpinner.fail();
myErr(err);
}
/**
* Creates the connection to the database.
*
* @param {err}
**/
function myErr(err) {
console.log(`[ERROR]`.red.bold, `${err.name}: ${err.message}`.red);
process.exit();
}
/**
@ -179,7 +210,6 @@ if (process.env.SECRETS) {
* @returns {Sequelize} Sequelize instance with the connection to the database.
*/
function createConnection() {
console.log('Creating the connection...');
return new Sequelize(process.env.DB_SCHEMA, process.env.DB_USER, process.env.DB_PWD, {
host: process.env.DB_HOST,
dialect: process.env.DB_DIALECT,