-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
122 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,37 @@ | ||
// require("dotenv").config(); | ||
require("dotenv").config(); | ||
|
||
// const config = { | ||
// development: { | ||
// url: process.env.DATABASE_DEVELOPMENT_URL, | ||
// dialect: "postgres", | ||
// dialectOptions: { | ||
// ssl: { | ||
// require: true, | ||
// rejectUnauthorized: true, | ||
// } | ||
// } | ||
// }, | ||
// test: { | ||
// url: process.env.DATABASE_TEST_URL, | ||
// dialect: "postgres", | ||
// dialectOptions: { | ||
// ssl: { | ||
// require: true, | ||
// rejectUnauthorized: true, | ||
// } | ||
// } | ||
// }, | ||
// production: { | ||
// url: process.env.DATABASE_PRODUCTION_URL, | ||
// dialect: "postgres", | ||
// dialectOptions: { | ||
// ssl: { | ||
// require: true, | ||
// rejectUnauthorized: true, | ||
// } | ||
// } | ||
// }, | ||
// }; | ||
|
||
// module.exports = config; | ||
|
||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
module.exports = { | ||
const config = { | ||
development: { | ||
username: process.env.DB_USERNAME || "postgres", | ||
password: process.env.DB_PASSWORD || "", | ||
database: process.env.DB_NAME || "postgres", | ||
host: process.env.DB_HOST || "127.0.0.1", | ||
url: process.env.DATABASE_DEVELOPMENT_URL, | ||
dialect: "postgres", | ||
dialectOptions: { | ||
ssl: { | ||
require: true, | ||
rejectUnauthorized: true, | ||
} | ||
} | ||
}, | ||
test: { | ||
username: process.env.DB_USERNAME || "postgres", | ||
password: process.env.DB_PASSWORD || "", | ||
database: process.env.DB_NAME || "postgres", | ||
host: process.env.DB_HOST || "127.0.0.1", | ||
url: process.env.DATABASE_TEST_URL, | ||
dialect: "postgres", | ||
dialectOptions: { | ||
ssl: { | ||
require: true, | ||
rejectUnauthorized: true, | ||
} | ||
} | ||
}, | ||
production: { | ||
username: process.env.DB_USERNAME || "postgres", | ||
password: process.env.DB_PASSWORD || "", | ||
database: process.env.DB_NAME || "postgres", | ||
host: process.env.DB_HOST || "127.0.0.1", | ||
url: process.env.DATABASE_PRODUCTION_URL, | ||
dialect: "postgres", | ||
dialectOptions: { | ||
ssl: { | ||
require: true, | ||
rejectUnauthorized: true, | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = config; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,38 @@ | ||
// import { config } from "dotenv"; | ||
// import { Sequelize } from "sequelize"; | ||
|
||
// config(); | ||
// const NODE_ENV: string = process.env.NODE_ENV || "development"; | ||
// const HOST_MODE: string = process.env.HOST_MODE || "remote"; | ||
|
||
// function getURL(): string { | ||
// switch (NODE_ENV) { | ||
// case "development": | ||
// return process.env.DATABASE_DEVELOPMENT_URL as string; | ||
// case "test": | ||
// return process.env.DATABASE_TEST_URL as string; | ||
// default: | ||
// return process.env.DATABASE_PRODUCTION_URL as string; | ||
// } | ||
// } | ||
|
||
// function getDialectOptions() { | ||
// return HOST_MODE === "local" | ||
// ? {} | ||
// : { | ||
// ssl: { | ||
// require: true, | ||
// rejectUnauthorized: false, | ||
// }, | ||
// }; | ||
// } | ||
|
||
// const connectSequelize: Sequelize = new Sequelize(getURL(), { | ||
// dialect: "postgres", | ||
// dialectOptions: getDialectOptions(), | ||
// logging: false, | ||
// }); | ||
|
||
// export default connectSequelize; | ||
|
||
import { config } from "dotenv"; | ||
import { Sequelize } from "sequelize"; | ||
const config = require("./config"); | ||
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const MODE: any = process.env.MODE || "development"; | ||
|
||
const currentConfig = config[`${MODE}`]; | ||
|
||
const connectSequelize: Sequelize = new Sequelize( | ||
currentConfig.database, | ||
currentConfig.username, | ||
currentConfig.password, | ||
{ | ||
host: currentConfig.host, | ||
dialect: currentConfig.dialect, | ||
dialectOptions: {}, | ||
config(); | ||
const NODE_ENV: string = process.env.NODE_ENV || "development"; | ||
const HOST_MODE: string = process.env.HOST_MODE || "remote"; | ||
|
||
function getURL(): string { | ||
switch (NODE_ENV) { | ||
case "development": | ||
return process.env.DATABASE_DEVELOPMENT_URL as string; | ||
case "test": | ||
return process.env.DATABASE_TEST_URL as string; | ||
default: | ||
return process.env.DATABASE_PRODUCTION_URL as string; | ||
} | ||
); | ||
} | ||
|
||
function getDialectOptions() { | ||
return HOST_MODE === "local" | ||
? {} | ||
: { | ||
ssl: { | ||
require: true, | ||
rejectUnauthorized: false, | ||
}, | ||
}; | ||
} | ||
|
||
const connectSequelize: Sequelize = new Sequelize(getURL(), { | ||
dialect: "postgres", | ||
dialectOptions: getDialectOptions(), | ||
logging: false, | ||
}); | ||
|
||
export default connectSequelize; | ||
|
||
|