Database setup for the Website service (#13)

This PR contains the work done to introduce a _Fluent_-based persistence layer for the Website service, selectable at runtime alongside the existing in-memory default, plus the local dev tooling and docs to support it.

To provide further details about the work:

* Persistence package
  * The `Driver` and `TLS` enumerations
  * The `Configuration` type
  * The `Service` factory that builds the  service
  * `PrepareDB` for migrations registration
  * The `Probe` for readiness checks.

* App integration
  *  Builds the driver, registers migrations, and attaches `Fluent` to the service lifecycle so it starts/stops with the HTTP server.
  * Migrate-on-boot is gated to the in-memory backend; MySQL/MariaDB is migrated out of band via --database-migrate so shared databases never race on startup.
  * The `ConfigReader+Properties` extension maps database.* config keys onto the driver.

* Library
  * Added database configuration constants.
  * The `HealthController` controller gains a readiness probe: `GET /health/ready` checks whether the database is reachable, separate from the existing liveness check.

* Others
  * Updated the `docker-compose` files to support a database service behind a database profile, and hardened for local development
  * New database targets on the `Makefile` file and overall documentation updated
  * Updated the `.env.local`, `Dockerfile`, and `README` files to document the persistence workflow, config keys, and local DB commands

Reviewed-on: rock-n-code/loud-amsterdam#13
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
2026-07-11 09:15:58 +00:00
committed by javier
parent 9774454bba
commit dc6b22e648
45 changed files with 1791 additions and 254 deletions
+60 -12
View File
@@ -38,36 +38,84 @@ pkg-clean: ## Remove the Swift build artifacts
@swift package clean
.PHONY: pkg-reset
pkg-reset: ## Resets the complete SPM cache/build folder
pkg-reset: ## Reset the SPM cache and build folder
@swift package reset
.PHONY: pkg-outdated
pkg-outdated: ## Lists the SPM package dependencies that can be updated
pkg-outdated: ## List the SPM dependencies that can be updated
@swift package update --dry-run
.PHONY: pkg-update
pkg-update: ## Updates the SPM package dependencies
pkg-update: ## Update the SPM dependencies
@swift package update
# --- Local development --------------------------------------------------------
.PHONY: img-build
img-build: ## Build the local dev image
@docker compose build
.PHONY: site-run
site-run: ## Run the website locally, rebuilding on source changes
@hb watch
.PHONY: img-mount
img-mount: ## Mount the service locally (build if needed)
@docker compose up --build --detach
.PHONY: site-mount
site-mount: ## Mount the website locally
@docker compose up \
--build \
--detach
.PHONY: img-unmount
img-unmount: ## Unmount and remove the local service
.PHONY: site-unmount
site-unmount: ## Unmount and remove the local website
@docker compose down
@$(MAKE) img-remove
# --- Local database -----------------------------------------------------------
.PHONY: db-mount
db-mount: ## Start the local database instance
@docker compose \
--profile database up \
--detach \
--wait mariadb
.PHONY: db-migrate
db-migrate: ## Run the migrations against the local database instance
@DATABASE_DRIVER=mysql \
DATABASE_HOST=127.0.0.1 \
DATABASE_TLS=off \
swift run \
Website \
--database-migrate
.PHONY: db-shell
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)
.PHONY: db-unmount
db-unmount: ## Stop and remove the local database instance (keeps the data volume)
@docker compose \
--profile database down mariadb
.PHONY: db-reset
db-reset: ## Stop and remove the local database instance and delete its data volume
@docker compose \
--profile database down mariadb \
--volumes
# --- Registry deployment ------------------------------------------------------
.PHONY: img-check
img-check: ## Check the production image builds
@docker build \
--platform linux/amd64 \
--file Dockerfile \
../..
.PHONY: img-release
img-release: ## Build the production (amd64) image, tag with version + latest, push both
img-release: ## Build and push the production image into the container registry
@if [ -z "$(version)" ] || [ "$(version)" = "latest" ]; then \
echo "Error: 'version' must be an explicit tag — e.g. make img-release version=1.2.3"; \
exit 1; \