feat: back up the database before migrating on deploy#65
Open
kevinsleegerslameco wants to merge 1 commit into
Open
feat: back up the database before migrating on deploy#65kevinsleegerslameco wants to merge 1 commit into
kevinsleegerslameco wants to merge 1 commit into
Conversation
Symfony/Kunstmaan deploys already run `database:migrate` before the
symlink switch, but with no safety net: `dep rollback` only repoints the
code symlink, and down() migrations are frequently lossy. A failed or
destructive migration on prod has no recovery path.
Add a `lameco:db_backup` task that writes a gzipped mariadb-dump
(--single-transaction) to shared/backups and prunes to the newest N, and
hook it `before('database:migrate', ...)` so every migrating deploy is
preceded by a restorable dump. Controlled by two settings (default on):
lameco_db_backup_on_deploy (bool, default true)
lameco_db_backup_keep (int, default 5)
If credentials can't be read the deploy halts rather than migrating
without a backup; set lameco_db_backup_on_deploy=false to opt out.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Symfony/Kunstmaan deploys already run
database:migrate(before('deploy:symlink', 'database:migrate')) — but with no backup.dep rollbackonly repoints the code symlink, anddown()migrations are frequently lossy, so a failed or destructive migration on prod has no recovery path. This is the real blocker before enabling auto-deploy to production.Adds
lameco:db_backupand hooks it beforedatabase:migrate, so every migrating deploy is preceded by a restorable dump.Changes
lameco:db_backup— gzippedmariadb-dump --quick --single-transactionintoshared/backups/<db>_<timestamp>.sql.gz, prunes to the newest N. Reuses the existingfetchEnv/extractDbCredentialshelpers; DB name passed via a shell var so it's safely quoted. Halts the deploy if credentials can't be read (won't migrate without a backup).before('database:migrate', 'lameco:db_backup'), only for symfony/kunstmaan and only when enabled.lameco_db_backup_on_deploy(defaulttrue),lameco_db_backup_keep(default5).Type of Change
Testing
php -lclean,vendor/bin/ecs checkclean.shared/backups/fills and prunes, then enable confidence for prod.Notes
database:migratehook), so they get no pre-migrate backup. If/when Craftcraft up-on-deploy is added, pair it with this task the same way.🤖 Generated with Claude Code