diff --git a/.sequelizerc b/.sequelizerc index e69de29b..4a5bacd3 100644 --- a/.sequelizerc +++ b/.sequelizerc @@ -0,0 +1,8 @@ +var path = require('path'); + +module.exports = { + config: path.resolve('src', 'config', 'config.json'), + 'migrations-path': path.resolve('migrations'), + 'models-path': path.resolve('src', 'models'), + 'seeders-path': path.resolve('seeders'), +}; diff --git a/migrations/20211207145446-staging.cjs b/migrations/20211207145446-staging.cjs index d4657c5c..325251c4 100644 --- a/migrations/20211207145446-staging.cjs +++ b/migrations/20211207145446-staging.cjs @@ -2,7 +2,7 @@ module.exports = { up: async (queryInterface, Sequelize) => { - await queryInterface.createTable('Staging', { + await queryInterface.createTable('Stagings', { id: { allowNull: false, autoIncrement: true, @@ -19,12 +19,20 @@ module.exports = { type: Sequelize.STRING, }, data: { - type: Sequelize.STRING, + type: Sequelize.STRING(10000), + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE, + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE, }, }); }, down: async (queryInterface, Sequelize) => { - await queryInterface.dropTable('Staging'); + await queryInterface.dropTable('Stagings'); }, }; diff --git a/src/config/config.json b/src/config/config.json index a56a03b4..7ab0ccac 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -1,5 +1,5 @@ { - "app_database": { + "development": { "dialect": "sqlite", "storage": "./data.sqlite3" }, diff --git a/src/models/database.js b/src/models/database.js index 4722012c..dd2d9d79 100644 --- a/src/models/database.js +++ b/src/models/database.js @@ -1,5 +1,4 @@ import { Sequelize } from 'sequelize'; -export const sequelize = new Sequelize('database', 'username', 'password', { - dialect: 'sqlite', - storage: './data.sqlite3', -}); +import config from '../config/config.json'; + +export const sequelize = new Sequelize(config['development']); diff --git a/src/models/staging/staging.model.js b/src/models/staging/staging.model.js index bc2e322a..8e2d10f2 100644 --- a/src/models/staging/staging.model.js +++ b/src/models/staging/staging.model.js @@ -24,11 +24,12 @@ Staging.init( table: Sequelize.STRING, action: Sequelize.STRING, data: Sequelize.STRING, + createdAt: Sequelize.DATE, + updatedAt: Sequelize.DATE, }, { sequelize, modelName: 'Staging', - timestamps: false, }, ); diff --git a/src/routes/index.js b/src/routes/index.js index 14e8913f..e090fe11 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -3,6 +3,8 @@ import express from 'express'; import bodyParser from 'body-parser'; import { V1Router } from './v1'; +import { sequelize } from '../models/database'; + const app = express(); app.use(express.json()); @@ -10,4 +12,6 @@ app.use(bodyParser.urlencoded({ extended: false })); app.use('/v1', V1Router); +sequelize.authenticate().then(() => console.log('Connected to database')); + export default app;