retropilot-server/models/index.model.js

45 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

/* eslint-disable no-restricted-syntax */
/* eslint-disable global-require */
import { Sequelize } from 'sequelize';
import devices from './devices.model';
import drives from './drives.model';
import users from './users.model';
import athena_action_log from './athena_action_log.model';
import athena_returned_data from './athena_returned_data.model';
import device_authorised_users from './device_authorised_users.model';
import drive_segments from './drive_segments.model';
import oauth_accounts from './oauth_accounts';
const sequelize = new Sequelize({
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME || 'retro-pilot',
host: process.env.DB_HOST || '127.0.0.1',
port: process.env.DB_PORT || 5432,
dialect: 'postgres',
});
sequelize.options.logging = () => {};
const modelDefiners = [
devices,
drives,
users,
athena_action_log,
athena_returned_data,
device_authorised_users,
drive_segments,
oauth_accounts,
];
for (const modelDefiner of modelDefiners) {
modelDefiner(sequelize);
}
// Create tables if they don't exist
// Update columns to match if the table already exists
sequelize.sync({ alter: true });
export default sequelize;