diff --git a/.sequelizerc b/.sequelizerc index e69de29b..ff92fa43 100644 --- a/.sequelizerc +++ b/.sequelizerc @@ -0,0 +1,8 @@ +var path = require('path'); + +module.exports = { + config: path.resolve('src', 'config', 'database.json'), + 'migrations-path': path.resolve('migrations'), + 'models-path': path.resolve('src', 'models'), + 'seeders-path': path.resolve('seeders'), +}; diff --git a/migrations/20211207145446-staging.js b/migrations/20211207145446-staging.js index d4657c5c..3e0c359f 100644 --- a/migrations/20211207145446-staging.js +++ b/migrations/20211207145446-staging.js @@ -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,12 @@ module.exports = { type: Sequelize.STRING, }, data: { - type: Sequelize.STRING, + type: Sequelize.STRING(10000), }, }); }, down: async (queryInterface, Sequelize) => { - await queryInterface.dropTable('Staging'); + await queryInterface.dropTable('Stagings'); }, }; diff --git a/src/config/database.json b/src/config/database.json new file mode 100644 index 00000000..2d2b6199 --- /dev/null +++ b/src/config/database.json @@ -0,0 +1,20 @@ +{ + "development": { + "dialect": "sqlite", + "storage": "./data.sqlite3" + }, + "test": { + "username": "root", + "password": null, + "database": "database_test", + "host": "127.0.0.1", + "dialect": "mysql" + }, + "production": { + "username": "root", + "password": null, + "database": "database_production", + "host": "127.0.0.1", + "dialect": "mysql" + } +} diff --git a/src/models/database.js b/src/models/database.js index a03c31d9..af4b6fbf 100644 --- a/src/models/database.js +++ b/src/models/database.js @@ -1,2 +1,11 @@ import { Sequelize } from 'sequelize'; -export const sequelize = new Sequelize('sqlite::memory:'); +import { fileURLToPath } from 'url'; +import { dirname, resolve } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +export const sequelize = new Sequelize({ + dialect: 'sqlite', + storage: resolve(`${__dirname}../../../data.sqlite3`), +}); 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;