Migrated the Website service tooling to use PostgreSQL instead.

This commit is contained in:
2026-08-05 01:26:54 +02:00
parent 9b4a780ea3
commit 6156cf5b0d
4 changed files with 33 additions and 35 deletions
+7 -7
View File
@@ -37,25 +37,25 @@ LOG_LEVEL=debug
# --- Persistence ----------------------------------------------------------------
# Persistence driver: inMemory (default, no infrastructure) or mysql.
# Persistence driver: inMemory (default, no infrastructure) or postgres.
DATABASE_DRIVER=inMemory
# MySQL/MariaDB connection, used when DATABASE_DRIVER=mysql.
# `mariadb` is the local database's Compose service name; use 127.0.0.1 when
# PostgreSQL connection, used when DATABASE_DRIVER=postgres.
# `postgres` is the local database's Compose service name; use 127.0.0.1 when
# running the app directly with `swift run`.
DATABASE_HOST=localhost
# Port of the database to connect to.
DATABASE_PORT=3306
DATABASE_PORT=5432
# Name of the database to connect to.
DATABASE_NAME=loud-ams
DATABASE_NAME=loud
# Username of the database to connect as.
DATABASE_USERNAME=loud-ams
DATABASE_USERNAME=loud
# Provide the real password via the environment or a secret — never commit it.
DATABASE_PASSWORD=loud-ams
DATABASE_PASSWORD=loud
# TLS posture when connecting: off | prefer | require (use `require` in production).
DATABASE_TLS=off
+10 -9
View File
@@ -73,11 +73,11 @@ db-mount: ## Start the local database instance
@docker compose \
--profile database up \
--detach \
--wait mariadb
--wait postgres
.PHONY: db-migrate
db-migrate: ## Run the migrations against the local database instance
@DATABASE_DRIVER=mysql \
@DATABASE_DRIVER=postgres \
DATABASE_HOST=127.0.0.1 \
DATABASE_TLS=off \
swift run \
@@ -88,21 +88,22 @@ db-migrate: ## Run the migrations against the local database instance
db-shell: ## Open a SQL shell on the local database instance
@docker compose \
--profile database \
exec mariadb \
mariadb \
--user=$(or $(DATABASE_USERNAME),loud) \
--password=$(or $(DATABASE_PASSWORD),loud) \
$(or $(DATABASE_NAME),loud)
exec \
--env PGPASSWORD=$(or $(DATABASE_PASSWORD),loud) \
postgres \
psql \
--username=$(or $(DATABASE_USERNAME),loud) \
--dbname=$(or $(DATABASE_NAME),loud)
.PHONY: db-unmount
db-unmount: ## Stop and remove the local database instance (keeps the data volume)
@docker compose \
--profile database down mariadb
--profile database down postgres
.PHONY: db-reset
db-reset: ## Stop and remove the local database instance and delete its data volume
@docker compose \
--profile database down mariadb \
--profile database down postgres \
--volumes
# --- Assets minification ------------------------------------------------------
+11 -14
View File
@@ -23,31 +23,28 @@ services:
# Local development database, started only with the `database` profile so a plain `docker compose up` still runs the
# in-memory backend:
#
# docker compose --profile database up mariadb
mariadb:
image: mariadb:11
# docker compose --profile database up postgres
postgres:
image: postgres:18
container_name: ${HOST_OWNER:-loud}-db
restart: unless-stopped
profiles:
- database
ports:
- "127.0.0.1:${DATABASE_PORT:-3306}:3306"
- "127.0.0.1:${DATABASE_PORT:-5432}:5432"
environment:
MARIADB_RANDOM_ROOT_PASSWORD: "yes"
MARIADB_DATABASE: ${DATABASE_NAME:-loud-ams}
MARIADB_USER: ${DATABASE_USERNAME:-loud-ams}
MARIADB_PASSWORD: ${DATABASE_PASSWORD:-loud-ams}
MARIADB_AUTO_UPGRADE: "1"
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_unicode_ci"
POSTGRES_DB: ${DATABASE_NAME:-loud}
POSTGRES_USER: ${DATABASE_USERNAME:-loud}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD:-loud}
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
test: ["CMD-SHELL", "pg_isready --username=$${POSTGRES_USER} --dbname=$${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 10
start_period: 30s
volumes:
- ./Tests/DB:/var/lib/mysql
# postgres:18 keeps its data directory under /var/lib/postgresql/<major>/docker, so the whole
# /var/lib/postgresql tree is mounted — not the pre-18 /var/lib/postgresql/data path.
- ./Tests/DB:/var/lib/postgresql
+5 -5
View File
@@ -20,13 +20,13 @@ services:
LOG_LEVEL: ${LOG_LEVEL:-info}
HTTP_SERVER_NAME: ${HTTP_SERVER_NAME:-LoudWebsite}
SECURITY_STRICT_TRANSPORT_SECURITY: "${SECURITY_STRICT_TRANSPORT_SECURITY:-max-age=31536000; includeSubDomains}"
# Persistence: in-memory by default; set DATABASE_DRIVER=mysql to run against a managed MySQL/MariaDB database.
# Persistence: in-memory by default; set DATABASE_DRIVER=postgres to run against a managed PostgreSQL database.
# Provide the password via the environment or a secret — never commit it.
DATABASE_DRIVER: ${DATABASE_DRIVER:-mysql}
DATABASE_DRIVER: ${DATABASE_DRIVER:-postgres}
DATABASE_HOST: ${DATABASE_HOST:-localhost}
DATABASE_PORT: ${DATABASE_PORT:-3306}
DATABASE_NAME: ${DATABASE_NAME:-loud-ams}
DATABASE_USERNAME: ${DATABASE_USERNAME:-loud-ams}
DATABASE_PORT: ${DATABASE_PORT:-5432}
DATABASE_NAME: ${DATABASE_NAME:-loud}
DATABASE_USERNAME: ${DATABASE_USERNAME:-loud}
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-}
DATABASE_TLS: ${DATABASE_TLS:-prefer}
healthcheck: