diff --git a/backend/src/prisma.service.ts b/backend/src/prisma.service.ts index c94decb4..631332ce 100644 --- a/backend/src/prisma.service.ts +++ b/backend/src/prisma.service.ts @@ -7,9 +7,10 @@ const DB_PWD = encodeURIComponent(process.env.POSTGRES_PASSWORD || "default"); / const DB_PORT = process.env.POSTGRES_PORT || 5432; const DB_NAME = process.env.POSTGRES_DATABASE || "postgres"; const DB_SCHEMA = process.env.POSTGRES_SCHEMA || "app"; +const DB_POOL_SIZE = parseInt(process.env.POSTGRES_POOL_SIZE || "5", 10); // SSL settings for PostgreSQL 17+ which requires SSL by default const SSL_MODE = (process.env.NODE_ENV === 'local' || 'unittest') ? 'prefer' : 'require'; // 'require' for aws deployments, 'prefer' for local development or ut in gha -const dataSourceURL = `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5&sslmode=${SSL_MODE}`; +const dataSourceURL = `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=${DB_POOL_SIZE}&sslmode=${SSL_MODE}`; @Injectable({ scope: Scope.DEFAULT}) class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { diff --git a/infrastructure/api/ecs.tf b/infrastructure/api/ecs.tf index 42a4db59..9ead134f 100644 --- a/infrastructure/api/ecs.tf +++ b/infrastructure/api/ecs.tf @@ -200,6 +200,10 @@ resource "aws_ecs_task_definition" "node_api_task" { name = "POSTGRES_SCHEMA" value = "${var.db_schema}" }, + { + name = "POSTGRES_POOL_SIZE" + value = "${var.postgres_pool_size}" + }, { name = "PORT" value = "3000" diff --git a/infrastructure/api/vars.tf b/infrastructure/api/vars.tf index b1c823dd..70552073 100644 --- a/infrastructure/api/vars.tf +++ b/infrastructure/api/vars.tf @@ -168,4 +168,9 @@ variable "is_public_api" { description = "Flag to indicate if the API is public or private" type = bool default = true +} +variable "postgres_pool_size" { + description = "The size of the connection pool for the API" + type = string + default = "1" } \ No newline at end of file diff --git a/infrastructure/database/vars.tf b/infrastructure/database/vars.tf index badfca74..39917b5d 100644 --- a/infrastructure/database/vars.tf +++ b/infrastructure/database/vars.tf @@ -38,7 +38,7 @@ variable "app_env" { variable "min_capacity" { description = "Minimum capacity for Aurora Serverless v2" type = number - default = 0.5 + default = 0 } variable "max_capacity" {