2023-01-09 10:59:07 +00:00
|
|
|
import { Sequelize } from 'sequelize';
|
|
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
2022-12-19 12:21:35 +00:00
|
|
|
|
2023-01-11 12:13:22 +00:00
|
|
|
let sequelize = createConnection();
|
2022-12-19 12:21:35 +00:00
|
|
|
|
2023-01-09 10:59:07 +00:00
|
|
|
import additionalPricePerPiece from './additionalPricePerPiece.js';
|
|
|
|
import botanicalNames from './botanicalNames.js';
|
|
|
|
import countryOfOriginIsoCodes from './countryOfOriginIsoCodes.js';
|
|
|
|
import packageModel from './package.js';
|
2023-01-10 12:24:43 +00:00
|
|
|
import packingConfigurations from './packingConfigurations.js';
|
2023-01-09 10:59:07 +00:00
|
|
|
import photos from './photos.js';
|
|
|
|
import seasonalPeriod from './seasonalPeriod.js';
|
|
|
|
import tradeItem from './tradeItem.js';
|
|
|
|
import clientConfig from './clientConfig.js';
|
|
|
|
import characteristics from './characteristics.js';
|
2022-12-19 12:21:35 +00:00
|
|
|
|
|
|
|
let models = {
|
|
|
|
additionalPricePerPiece: additionalPricePerPiece(sequelize),
|
|
|
|
botanicalNames: botanicalNames(sequelize),
|
|
|
|
countryOfOriginIsoCodes: countryOfOriginIsoCodes(sequelize),
|
|
|
|
package: packageModel(sequelize),
|
2023-01-10 12:24:43 +00:00
|
|
|
packingConfigurations: packingConfigurations(sequelize),
|
2022-12-19 12:21:35 +00:00
|
|
|
photos: photos(sequelize),
|
|
|
|
seasonalPeriod: seasonalPeriod(sequelize),
|
|
|
|
tradeItem: tradeItem(sequelize),
|
|
|
|
clientConfig: clientConfig(sequelize),
|
|
|
|
characteristics: characteristics(sequelize),
|
|
|
|
};
|
|
|
|
|
2023-01-11 12:13:22 +00:00
|
|
|
if (process.env.FORCE_SYNC) {
|
2023-01-09 10:59:07 +00:00
|
|
|
console.log('Syncing the models...');
|
|
|
|
await sequelize.sync({ force: true });
|
2023-01-10 12:24:43 +00:00
|
|
|
}
|
2023-01-09 11:08:30 +00:00
|
|
|
|
2023-01-11 12:13:22 +00:00
|
|
|
if (process.env.SECRETS) {
|
2023-01-09 11:08:30 +00:00
|
|
|
await models.clientConfig.create({
|
|
|
|
clientId: process.env.CLIENT_ID,
|
|
|
|
clientSecret: process.env.CLIENT_SECRET,
|
|
|
|
});
|
2023-01-09 09:06:34 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 12:13:22 +00:00
|
|
|
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,
|
|
|
|
logging: false,
|
|
|
|
pool: {
|
|
|
|
max: 20,
|
|
|
|
min: 0,
|
|
|
|
acquire: 60000,
|
|
|
|
idle: 10000,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export { models } ;
|