Skip to content

Commit e92961e

Browse files
author
guilherme
committed
feat(database): add psql_bouncer support and simplify postgresql config
- Add new psql_bouncer database provider option - Update database scripts to handle psql_bouncer provider - Comment out pgbouncer service in docker-compose - Simplify postgresql schema by removing directUrl - Add new psql_bouncer-schema.prisma file - Update .env.example with psql_bouncer configuration - Modify runWithProvider.js to handle psql_bouncer migrations
1 parent 09429e6 commit e92961e

File tree

7 files changed

+797
-26
lines changed

7 files changed

+797
-26
lines changed

.env.example

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ EVENT_EMITTER_MAX_LISTENERS=50
2727
# If you don't even want an expiration, enter the value false
2828
DEL_INSTANCE=false
2929

30-
# Provider: postgresql | mysql
30+
# Provider: postgresql | mysql | psql_bouncer
3131
DATABASE_PROVIDER=postgresql
32-
DATABASE_CONNECTION_URI='postgresql://user:pass@postgres:6543/evolution_db?pgbouncer=true&schema=evolution_api'
33-
DATABASE_DIRECT_CONNECTION_URI=postgresql://user:pass@postgres:5432/evolution_db?schema=evolution_api
32+
DATABASE_CONNECTION_URI='postgresql://user:pass@postgres:5432/evolution_db?schema=evolution_api'
3433
# Client name for the database connection
3534
# It is used to separate an API installation from another that uses the same database.
3635
DATABASE_CONNECTION_CLIENT_NAME=evolution_exchange
3736

37+
# Bouncer connection: used only when the database provider is set to 'psql_bouncer'.
38+
# Defines the PostgreSQL URL with pgbouncer enabled (pgbouncer=true).
39+
# DATABASE_BOUNCER_CONNECTION_URI=postgresql://user:pass@pgbouncer:5432/evolution_db?pgbouncer=true&schema=evolution_api
40+
3841
# Choose the data you want to save in the application's database
3942
DATABASE_SAVE_DATA_INSTANCE=true
4043
DATABASE_SAVE_DATA_NEW_MESSAGE=true

Docker/scripts/deploy_database.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ "$DOCKER_ENV" != "true" ]; then
66
export_env_vars
77
fi
88

9-
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
9+
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then
1010
export DATABASE_URL
1111
echo "Deploying migrations for $DATABASE_PROVIDER"
1212
echo "Database URL: $DATABASE_URL"

Docker/scripts/generate_database.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ "$DOCKER_ENV" != "true" ]; then
66
export_env_vars
77
fi
88

9-
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
9+
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then
1010
export DATABASE_URL
1111
echo "Generating database for $DATABASE_PROVIDER"
1212
echo "Database URL: $DATABASE_URL"
@@ -20,4 +20,4 @@ if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]
2020
else
2121
echo "Error: Database provider $DATABASE_PROVIDER invalid."
2222
exit 1
23-
fi
23+
fi

docker-compose.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ services:
5454
volumes:
5555
- postgres_data:/var/lib/postgresql/data
5656

57-
pgbouncer:
58-
image: edoburu/pgbouncer:latest
59-
environment:
60-
DB_HOST: postgres
61-
DB_USER: user
62-
DB_PASSWORD: pass
63-
POOL_MODE: transaction
64-
AUTH_TYPE: trust
65-
MAX_CLIENT_CONN: 1000
66-
DEFAULT_POOL_SIZE: 25
67-
depends_on:
68-
- postgres
69-
ports:
70-
- "6543:5432"
71-
networks:
72-
- evolution-net
57+
# pgbouncer:
58+
# image: edoburu/pgbouncer:latest
59+
# environment:
60+
# DB_HOST: postgres
61+
# DB_USER: user
62+
# DB_PASSWORD: pass
63+
# POOL_MODE: transaction
64+
# AUTH_TYPE: trust
65+
# MAX_CLIENT_CONN: 1000
66+
# DEFAULT_POOL_SIZE: 25
67+
# depends_on:
68+
# - postgres
69+
# ports:
70+
# - "6543:5432"
71+
# networks:
72+
# - evolution-net
7373

7474
volumes:
7575
evolution_instances:

prisma/postgresql-schema.prisma

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ generator client {
99
}
1010

1111
datasource db {
12-
provider = "postgresql"
13-
url = env("DATABASE_CONNECTION_URI")
14-
directUrl = env("DATABASE_DIRECT_CONNECTION_URI")
12+
provider = "postgresql"
13+
url = env("DATABASE_CONNECTION_URI")
1514
}
1615

1716
enum InstanceConnectionStatus {

0 commit comments

Comments
 (0)