floriday/models/index.js

59 lines
1.8 KiB
JavaScript

import { Sequelize } from 'sequelize';
import dotenv from 'dotenv';
dotenv.config();
let sequelize = createConnection();
import additionalPricePerPiece from './additionalPricePerPiece.js';
import botanicalNames from './botanicalNames.js';
import countryOfOriginIsoCodes from './countryOfOriginIsoCodes.js';
import packageModel from './package.js';
import packingConfigurations from './packingConfigurations.js';
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';
let models = {
additionalPricePerPiece: additionalPricePerPiece(sequelize),
botanicalNames: botanicalNames(sequelize),
countryOfOriginIsoCodes: countryOfOriginIsoCodes(sequelize),
package: packageModel(sequelize),
packingConfigurations: packingConfigurations(sequelize),
photos: photos(sequelize),
seasonalPeriod: seasonalPeriod(sequelize),
tradeItem: tradeItem(sequelize),
clientConfig: clientConfig(sequelize),
characteristics: characteristics(sequelize),
};
if (process.env.FORCE_SYNC) {
console.log('Syncing the models...');
await sequelize.sync({ force: true });
}
if (process.env.SECRETS) {
await models.clientConfig.create({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
});
}
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 } ;