feat: Add optional config of database connection pooling

This commit is contained in:
Tom Moor
2022-03-17 18:18:35 -07:00
parent 018593a6aa
commit c98c397fa8
2 changed files with 10 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ UTILS_SECRET=generate_a_new_key
# should work out of the box.
DATABASE_URL=postgres://user:pass@localhost:5432/outline
DATABASE_URL_TEST=postgres://user:pass@localhost:5432/outline-test
DATABASE_CONNECTION_POOL_MIN=
DATABASE_CONNECTION_POOL_MAX=
# Uncomment this to disable SSL for connecting to Postgres
# PGSSLMODE=disable
REDIS_URL=redis://localhost:6379

View File

@@ -4,6 +4,8 @@ import * as models from "../models";
const isProduction = process.env.NODE_ENV === "production";
const isSSLDisabled = process.env.PGSSLMODE === "disable";
const poolMax = parseInt(process.env.DATABASE_CONNECTION_POOL_MAX || "5", 10);
const poolMin = parseInt(process.env.DATABASE_CONNECTION_POOL_MIN || "0", 10);
export const sequelize = new Sequelize(
process.env.DATABASE_URL || process.env.DATABASE_CONNECTION_POOL_URL || "",
@@ -20,5 +22,11 @@ export const sequelize = new Sequelize(
: false,
},
models: Object.values(models),
pool: {
max: poolMax,
min: poolMin,
acquire: 30000,
idle: 10000,
},
}
);