Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add new env vars for db #712

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export E2E_TEST_GH_TOKEN=""
export DB_URI="postgres://isomer:password@localhost:15432/isomercms_dev"
export DB_MIN_POOL="1"
export DB_MAX_POOL="10"
export DB_ACQUIRE="60000"
export DB_TIMEOUT="30000"
export DB_ENABLE_LOGGING=""

export LOCAL_SITE_ACCESS_TOKEN=""
Expand Down
14 changes: 14 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ const config = convict({
format: "required-positive-number",
default: 10,
},
dbAcquire: {
doc:
"The maximum time, in milliseconds, that pool will try to get connection before throwing error",
env: "DB_ACQUIRE",
format: "required-positive-number",
default: 60000,
},
dbTimeout: {
doc:
"The maximum time, in milliseconds, before an idle session within an open transaction will be terminated",
env: "DB_TIMEOUT",
format: "required-positive-number",
default: 10000,
},
dbEnableLogging: {
doc: "Enable database logging",
env: "DB_ENABLE_LOGGING",
Expand Down
4 changes: 4 additions & 0 deletions src/database/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const { parse } = require("pg-connection-string")
const { DB_URI } = process.env
const DB_MIN_POOL = parseInt(process.env.DB_MIN_POOL, 10)
const DB_MAX_POOL = parseInt(process.env.DB_MAX_POOL, 10)
const DB_ACQUIRE = parseInt(process.env.DB_ACQUIRE, 10)
const DB_TIMEOUT = parseInt(process.env.DB_TIMEOUT, 10)

const parsed = parse(DB_URI)
const port = parsed.port ? parseInt(parsed.port, 10) : 5432
Expand All @@ -27,6 +29,7 @@ module.exports = {
dialectOptions: {
useUTC: false,
timezone: "+08:00",
idle_in_transaction_session_timeout: DB_TIMEOUT,
},
timezone: "+08:00",
define: {
Expand All @@ -38,5 +41,6 @@ module.exports = {
pool: {
min: DB_MIN_POOL,
max: DB_MAX_POOL,
acquire: DB_ACQUIRE,
},
}