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