Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
fix: PG ssl (#306)
Browse files Browse the repository at this point in the history
* fix: use full db config in app rather than only for migrations

* fix: reenable require ssl on prod and redisable on dev

* fix: fix CI

* fix ci

* fix ci

* fix ci
  • Loading branch information
achauve authored Nov 24, 2023
1 parent eaa7c47 commit ba372c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
20 changes: 11 additions & 9 deletions src/db/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ dotenv.config();

module.exports = {
development: {
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",
url: process.env.DATABASE_URL,
dialectOptions: {
ssl: {
require: false,
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,
require: true,
rejectUnauthorized: false,
},
},
Expand Down
23 changes: 16 additions & 7 deletions src/db/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { Sequelize } from "sequelize";

import config from "../../services/config";
import dbConfig from "../config/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] || dbConfig["development"];

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),
Expand Down
1 change: 0 additions & 1 deletion src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ba372c0

Please sign in to comment.