feat(migrations): run Liquibase migrations automatically on stack start#79
Conversation
Remove the `migrate` profile gate from the liquibase-auth service so it runs unconditionally on every `docker compose up`. Switch auth-api to use the docker-entrypoint.sh (which creates schemas then runs Liquibase) and add a `depends_on: liquibase-auth: service_completed_successfully` condition so auth-api never starts against an un-migrated database. Update docker-compose.override.yaml.example to reflect that no manual migration step is required. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Docker Compose configuration is restructured to manage Liquibase database migrations automatically through service dependency ordering rather than explicit profile invocation. The auth-api service now depends on liquibase-auth with a wait condition for successful completion, while liquibase-auth switches from command-based execution to a shell entrypoint approach. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.Change the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docker-compose.yaml`:
- Line 117: The service currently hard-codes the behavior by invoking
migrations/docker-entrypoint.sh which itself runs liquibase ... update without
forwarding arguments; change the service to specify command: ["update"] (so
docker-compose commands like status or rollback become args instead of being
ignored) and update migrations/docker-entrypoint.sh to forward any passed
arguments to liquibase (use "$@" when invoking liquibase) and default to
"update" when no args are provided (e.g., if [ $# -eq 0 ]; then set
args=("update"); fi; then run liquibase ... "${args[@]}" or equivalent).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5fb8c5b5-6e7c-48e1-8e8e-bfcb1729dd0a
📒 Files selected for processing (2)
docker-compose.override.yaml.exampledocker-compose.yaml
| LIQUIBASE_LOG_LEVEL: INFO | ||
| volumes: | ||
| - ./migrations:/liquibase/changelog:ro | ||
| entrypoint: ["/bin/sh", "/liquibase/changelog/docker-entrypoint.sh"] |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== docker-compose.yaml =="
sed -n '115,120p' docker-compose.yaml
echo
echo "== migrations/docker-entrypoint.sh =="
sed -n '1,40p' migrations/docker-entrypoint.sh
echo
echo "== argument forwarding check =="
if rg -n '\$@|"\$@"' migrations/docker-entrypoint.sh; then
echo "argument forwarding found"
else
echo "no argument forwarding found"
fi
echo
echo "== documented manual Liquibase commands =="
sed -n '23,56p' migrations/README.mdRepository: heysarver/auth-api
Length of output: 2337
Don't hard-code update in the service entrypoint.
The script at migrations/docker-entrypoint.sh ends with liquibase --defaults-file=/tmp/liquibase.properties update and does not forward arguments. This causes a behavioral regression: users running documented commands like docker compose --profile migrate run --rm liquibase-auth status --verbose, updateSQL, or rollback-count 1 will silently execute migrations instead of the requested action. These workflows are still documented in migrations/README.md:23-56.
To fix, add command: ["update"] to the service and modify the script to forward arguments:
Proposed fix
entrypoint: ["/bin/sh", "/liquibase/changelog/docker-entrypoint.sh"]
+ command: ["update"]-echo "Running Liquibase migrations for auth schema..."
-liquibase --defaults-file=/tmp/liquibase.properties update
-
-echo "Migrations completed successfully!"
+if [ "$#" -eq 0 ]; then
+ set -- update
+fi
+
+echo "Running Liquibase command: $*"
+liquibase --defaults-file=/tmp/liquibase.properties "$@"
+
+echo "Liquibase command completed successfully!"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docker-compose.yaml` at line 117, The service currently hard-codes the
behavior by invoking migrations/docker-entrypoint.sh which itself runs liquibase
... update without forwarding arguments; change the service to specify command:
["update"] (so docker-compose commands like status or rollback become args
instead of being ignored) and update migrations/docker-entrypoint.sh to forward
any passed arguments to liquibase (use "$@" when invoking liquibase) and default
to "update" when no args are provided (e.g., if [ $# -eq 0 ]; then set
args=("update"); fi; then run liquibase ... "${args[@]}" or equivalent).
Summary
migrateprofile gate fromliquibase-authso migrations run unconditionally on everydocker compose upliquibase-authto usedocker-entrypoint.sh(creates schemas then runs Liquibase) instead of a bareliquibase updatecommanddepends_on: liquibase-auth: condition: service_completed_successfullytoauth-apiso the app never starts against an un-migrated databasedocker-compose.override.yaml.exampleto reflect that no manual migration step is neededTest plan
docker compose up -dfrom theauth-apidirectory (with override) against a blank database and confirmliquibase-authruns and exits 0 beforeauth-apistartsauth-apistarts healthy after migrations completedocker compose up -da second time (migrations already applied) and confirmliquibase-authexits 0 (no-op) andauth-apistarts normally🤖 Generated with Claude Code
Summary by CodeRabbit