<commit_before>'use strict';

const fs = require('fs');
const path = require('path');

const Sequelize = require('sequelize');

let db;

const config = {
  username: process.env.DB_USERNAME || 'root',
  password: process.env.DB_PASSWORD || <PASSWORD>,
  database: process.env.DB_NAME || 'example',
  host: process.env.DB_HOST || '127.0.0.1',
  port: process.env.DB_PORT || 5432,
  dialect: process.env.DB_DIALECT || 'postgres'
};

const sequelize = new Sequelize(config.database, config.username, config.password, config);

module.exports = db = { sequelize, Sequelize };

loadModels(db);
doAssociations(db);

function loadModels (db) {
  return ['shared', 'admin', 'catalog'].map((type) => {
    return readDir(type);
  });
}

function doAssociations (db) {
  Object.keys(db).forEach((modelName) => {
    if ('associate' in db[modelName]) {
      db[modelName].associate(db);
    }
  });

  return;
}

function readDir (type) {
  return fs.readdirSync(path.join('src', type))
    .filter((dir) => {
      return dir.match(/^[^.]/);
    })
    .map((entity) => {
      const root = path.join(__dirname, '..', type, entity, 'model.js');

      try {
        fs.statSync(root).isFile();
      } catch (err) {
        return;
      }

      let model = sequelize['import'](root);
      db[model.name] = model;
    });
}<commit_msg>Upate core database for new bootstrap<commit_after>'use strict';

const Sequelize = require('sequelize');

const config = {
  username: process.env.DB_USERNAME || 'root',
  password: process.env.DB_PASSWORD || <PASSWORD>,
  database: process.env.DB_NAME || 'example',
  host: process.env.DB_HOST || '127.0.0.1',
  port: process.env.DB_PORT || 5432,
  dialect: process.env.DB_DIALECT || 'postgres'
};

const sequelize = new Sequelize(config.database, config.username, config.password, config);

module.exports = { sequelize, Sequelize, doAssociations };

function doAssociations (db) {
  Object.keys(db).forEach((modelName) => {
    if ('associate' in db[modelName]) {
      db[modelName].associate(db);
    }
  });

  return;
}
{'fraction_non_alphanumeric': 0.17420924574209246, 'fraction_numerical': 0.009732360097323601, 'mean_word_length': 3.737327188940092, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '194655', 'n_tokens_mistral': 724, 'n_tokens_neox': 703, 'n_words': 142}