From b33832193453cc47f7a9a2e352c006b7741af20d Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Thu, 23 Nov 2023 15:01:58 +0100 Subject: [PATCH 1/6] fix: use full db config in app rather than only for migrations --- src/db/config/config.js | 14 +++++++++++--- src/db/models/index.ts | 23 ++++++++++++++++------- src/services/config.ts | 1 - 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/db/config/config.js b/src/db/config/config.js index e5317c03..ae3479a3 100644 --- a/src/db/config/config.js +++ b/src/db/config/config.js @@ -3,18 +3,26 @@ dotenv.config(); module.exports = { development: { + username: process.env.PGUSER, + password: process.env.PGPASSWORD, + database: process.env.PGDATABASE, + port: process.env.PGPORT, + host: process.env.PGHOST, dialect: "postgres", - url: process.env.DATABASE_URL, dialectOptions: { ssl: { - require: false, + require: true, rejectUnauthorized: false, }, }, }, production: { + username: process.env.PGUSER, + password: process.env.PGPASSWORD, + database: process.env.PGDATABASE, + port: process.env.PGPORT, + host: process.env.PGHOST, dialect: "postgres", - url: process.env.DATABASE_URL, dialectOptions: { ssl: { require: false, diff --git a/src/db/models/index.ts b/src/db/models/index.ts index 062489d0..255fa398 100644 --- a/src/db/models/index.ts +++ b/src/db/models/index.ts @@ -1,15 +1,24 @@ import { Sequelize } from "sequelize"; +import dbConfig from "../config/config"; import config from "../../services/config"; import psychologist from "./psychologist"; -export const sequelize = new Sequelize(config.postgre.url, { - define: { - freezeTableName: true, - }, - dialect: "postgres", - logging: config.postgre.logging ? console.log : false, -}); +const env = process.env.NODE_ENV || "development"; +const currentDbConfig = dbConfig[env]; + +export const sequelize = new Sequelize( + currentDbConfig.database, + currentDbConfig.username, + currentDbConfig.password, + { + ...currentDbConfig, + define: { + freezeTableName: true, + }, + logging: config.postgre.logging ? console.log : false, + } +); export const models = { Psychologist: psychologist(sequelize), diff --git a/src/services/config.ts b/src/services/config.ts index 9b53a547..c2e88574 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -43,7 +43,6 @@ export default { minScoreAddress: parseFloat(process.env.MIN_SCORE_ADDRESS || "0.30"), postgre: { logging: parseBoolean(process.env.DB_LOGGING_ENABLE), - url: process.env.DATABASE_URL || "postgres://localhost:5432/monpsysante", }, supportMail: process.env.SUPPORT_MAIL, reportingMailRecipients: process.env.REPORTING_MAIL_RECIPIENTS, From adfcd4e37ce0a9f808a97e21da32ca951e149f07 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Thu, 23 Nov 2023 15:08:52 +0100 Subject: [PATCH 2/6] fix: reenable require ssl on prod and redisable on dev --- src/db/config/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/db/config/config.js b/src/db/config/config.js index ae3479a3..90fc29ff 100644 --- a/src/db/config/config.js +++ b/src/db/config/config.js @@ -11,7 +11,7 @@ module.exports = { dialect: "postgres", dialectOptions: { ssl: { - require: true, + require: false, rejectUnauthorized: false, }, }, @@ -25,7 +25,7 @@ module.exports = { dialect: "postgres", dialectOptions: { ssl: { - require: false, + require: true, rejectUnauthorized: false, }, }, From b02b5cb36fd7b00298818131973e05635e077857 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Thu, 23 Nov 2023 15:18:35 +0100 Subject: [PATCH 3/6] fix: fix CI --- src/db/config/config.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/db/config/config.js b/src/db/config/config.js index 90fc29ff..99e407d5 100644 --- a/src/db/config/config.js +++ b/src/db/config/config.js @@ -9,12 +9,6 @@ module.exports = { port: process.env.PGPORT, host: process.env.PGHOST, dialect: "postgres", - dialectOptions: { - ssl: { - require: false, - rejectUnauthorized: false, - }, - }, }, production: { username: process.env.PGUSER, From 5770309ceab2e58870c40450b5c5d711c0e28119 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Thu, 23 Nov 2023 15:30:04 +0100 Subject: [PATCH 4/6] fix ci --- src/db/config/config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/db/config/config.js b/src/db/config/config.js index 99e407d5..2196dc25 100644 --- a/src/db/config/config.js +++ b/src/db/config/config.js @@ -3,9 +3,9 @@ dotenv.config(); module.exports = { development: { - username: process.env.PGUSER, - password: process.env.PGPASSWORD, - database: process.env.PGDATABASE, + username: process.env.PGUSER || "monpsysante", + password: process.env.PGPASSWORD || "monpsysante", + database: process.env.PGDATABASE || "monpsysante", port: process.env.PGPORT, host: process.env.PGHOST, dialect: "postgres", From 00c21dbc287ace4bada0eae697c4c3e545eed3b0 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Thu, 23 Nov 2023 15:36:12 +0100 Subject: [PATCH 5/6] fix ci --- src/db/models/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/index.ts b/src/db/models/index.ts index 255fa398..5fad0806 100644 --- a/src/db/models/index.ts +++ b/src/db/models/index.ts @@ -1,7 +1,7 @@ import { Sequelize } from "sequelize"; -import dbConfig from "../config/config"; import config from "../../services/config"; +import dbConfig from "../config/config"; import psychologist from "./psychologist"; const env = process.env.NODE_ENV || "development"; From 80643050bd30a5fa4159d5e7a6655809dc508690 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Thu, 23 Nov 2023 17:07:38 +0100 Subject: [PATCH 6/6] fix ci --- src/db/models/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/index.ts b/src/db/models/index.ts index 5fad0806..0e255d22 100644 --- a/src/db/models/index.ts +++ b/src/db/models/index.ts @@ -5,7 +5,7 @@ import dbConfig from "../config/config"; import psychologist from "./psychologist"; const env = process.env.NODE_ENV || "development"; -const currentDbConfig = dbConfig[env]; +const currentDbConfig = dbConfig[env] || dbConfig["development"]; export const sequelize = new Sequelize( currentDbConfig.database,