From dea6b928e155295a31076591be6a5f7055b79b6c Mon Sep 17 00:00:00 2001 From: Adrien Date: Sun, 22 Jan 2023 19:02:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Create=20and=20use=20a?= =?UTF-8?q?=20db=20dedicated=20user=20for=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rename the db name (idfm_matrix_bot -> cer_db). * Remove unused bot database. * Create a dedicated user (cer_user/cer_password). --- .../docker-entrypoint-initdb.d/init-user-db.sh | 10 +++++----- backend/main.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/docker/database/docker-entrypoint-initdb.d/init-user-db.sh b/backend/docker/database/docker-entrypoint-initdb.d/init-user-db.sh index 9b9f4ef..ca03242 100755 --- a/backend/docker/database/docker-entrypoint-initdb.d/init-user-db.sh +++ b/backend/docker/database/docker-entrypoint-initdb.d/init-user-db.sh @@ -2,10 +2,10 @@ set -e psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL - CREATE USER idfm_matrix_bot; - CREATE DATABASE bot; - CREATE DATABASE idfm; - GRANT ALL PRIVILEGES ON DATABASE bot TO idfm_matrix_bot; - GRANT ALL PRIVILEGES ON DATABASE idfm TO idfm_matrix_bot; + CREATE USER cer_user WITH ENCRYPTED password 'cer_password'; + CREATE DATABASE cer_db; + \c cer_db; + CREATE EXTENSION IF NOT EXISTS pg_trgm SCHEMA "public"; + GRANT CREATE ON SCHEMA public to cer_user; EOSQL diff --git a/backend/main.py b/backend/main.py index e06f843..d5a6f14 100644 --- a/backend/main.py +++ b/backend/main.py @@ -24,7 +24,7 @@ API_KEY = environ.get("API_KEY") # TODO: Add error message if no key is given. # TODO: Remove postgresql+asyncpg from environ variable -DB_PATH = "postgresql+asyncpg://postgres:postgres@127.0.0.1:5438/idfm" +DB_PATH = "postgresql+asyncpg://cer_user:cer_password@127.0.0.1:5438/cer_db" app = FastAPI()