Skip to content

Commit

Permalink
Add sqlz, add migration into entrypoint
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Sachivka <juicy.igor@gmail.com>
  • Loading branch information
isachivka committed May 15, 2023
1 parent eaf063f commit 95a283c
Show file tree
Hide file tree
Showing 9 changed files with 1,938 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
module.exports = {
'config': path.resolve('database', 'config.js'),
'models-path': path.resolve('src/pg', 'models'),
'seeders-path': path.resolve('database', 'seeders'),
'migrations-path': path.resolve('database', 'migrations')
};
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ RUN npm run build

EXPOSE 3000

ENTRYPOINT ["node", "dist/index.js"]
ENTRYPOINT npm run migrate && node dist/index.js

33 changes: 33 additions & 0 deletions database/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require("dotenv").config();

console.log({
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: "postgres",
});

module.exports = {
development: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: "postgres",
},
test: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: "postgres",
},
production: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: "postgres",
},
};
36 changes: 36 additions & 0 deletions database/migrations/20230515194611-create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable("users", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
userId: {
type: Sequelize.BIGINT,
},
chatId: {
type: Sequelize.BIGINT,
},
auth: {
type: Sequelize.BOOLEAN,
},
token: {
type: Sequelize.STRING,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
},
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable("users");
},
};
Loading

0 comments on commit 95a283c

Please sign in to comment.