start
This commit is contained in:
parent
55a57444f8
commit
8e86f72975
4 changed files with 57 additions and 1 deletions
6
.sequelizerc
Normal file
6
.sequelizerc
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
config: path.resolve('src', 'database', 'config.js'),
|
||||
'migrations-path': path.resolve('src', 'database', 'migrations'),
|
||||
};
|
||||
20
src/database/config.js
Normal file
20
src/database/config.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
const dotenv = require('dotenv');
|
||||
|
||||
dotenv.config();
|
||||
|
||||
module.exports = {
|
||||
development: {
|
||||
dialect: 'postgres',
|
||||
host: process.env.POSTGRES_HOST,
|
||||
port: 5432,
|
||||
database: process.env.POSTGRES_DB,
|
||||
username: process.env.POSTGRES_USER,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
define: {
|
||||
timestamps: false,
|
||||
freezeTableName: true,
|
||||
underscored: true,
|
||||
quoteIdentifiers: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
30
src/database/migrations/20250308000000-create-table.js
Normal file
30
src/database/migrations/20250308000000-create-table.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('Users', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER,
|
||||
},
|
||||
firstName: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
lastName: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE,
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE,
|
||||
},
|
||||
});
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('Users');
|
||||
},
|
||||
};
|
||||
|
|
@ -5,7 +5,7 @@ function buildDependencies() {
|
|||
const errors = require('./errors');
|
||||
const constants = require('./constants');
|
||||
|
||||
const sequelize = require('./database');
|
||||
const sequelize = require('./database/database');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const ModelsProvider = require('./models');
|
||||
const models = new ModelsProvider({ sequelize, DataTypes }).provide();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue