-
Notifications
You must be signed in to change notification settings - Fork 130
chore(scripts): add pg backup & restore scripts for dev #3251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(scripts): add pg backup & restore scripts for dev #3251
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Code ReviewThanks for adding these PostgreSQL backup and restore scripts! This is a useful addition for development workflows. Here's my feedback: ✅ Strengths
🐛 Potential Issues1. Volume persistence issue in
|
3b132f6 to
be4b98e
Compare
a27327f to
0ffdb8b
Compare
Code ReviewOverall, this is a solid addition to the development tooling! The backup and restore scripts will be very useful for managing local development databases. Here's my detailed feedback: ✅ Strengths
🐛 Potential IssuesCritical: Volume Handling in restore-postgres.shIssue: Location: # Creates a brand new volume every time
VOLUME_NAME=$(docker volume create)Recommendation: Extract the volume name before removing the container (like
Suggested fix: # Get the old volume name if container exists
OLD_VOLUME_NAME=""
if docker ps --all --format '{{.Names}}' | grep -qw "${CONTAINER_NAME}"; then
OLD_VOLUME_NAME=$(docker inspect "${CONTAINER_NAME}" --format '{{range .Mounts}}{{if eq .Destination "/var/lib/postgresql/data"}}{{.Name}}{{end}}{{end}}' 2>/dev/null || true)
fi
# Stop and remove existing container
# ... existing code ...
# Remove old volume if it exists
if [ -n "${OLD_VOLUME_NAME}" ]; then
echo "Removing old volume '${OLD_VOLUME_NAME}'..."
docker volume rm "${OLD_VOLUME_NAME}" >/dev/null 2>&1 || true
fi
# Create a new volume
VOLUME_NAME=$(docker volume create)Missing Volume Handling in postgres.shIssue: The base Location: Recommendation: Consider whether 🔒 Security Considerations
⚡ Performance Considerations
📝 Code Quality & Best Practices
🧪 Testing SuggestionsConsider testing these scenarios:
📖 DocumentationConsider adding a README in
Minor Suggestions
Summary: The implementation is solid, but please address the volume cleanup issue in Great work on improving the dev tooling! 🚀 |
PR Review: chore(scripts): add pg backup & restore scripts for devSummaryThis PR adds helpful developer tooling for managing PostgreSQL backups and data lifecycle. The changes include backup, restore, and nuke scripts, plus an enhancement to auto-start postgres when needed. Code Quality & Best PracticesStrengths:
Issues & Suggestions: 1. Volume naming in postgres.sh (scripts/run/postgres.sh:14-21)The original postgres.sh doesn't create a named volume, which makes the backup scripts rely on inspecting the container to find the anonymous volume. Consider using a named volume for consistency - this would simplify the backup scripts and make the volume easier to manage. 2. Race condition in engine-postgres.sh (scripts/run/engine-postgres.sh:19-27)The postgres readiness check uses nc to test port connectivity, but this doesn't guarantee postgres is ready to accept queries. PostgreSQL may accept connections before it's fully initialized. Consider using pg_isready via docker exec instead. 3. Error handling in backup-postgres.sh (scripts/run/backup-postgres.sh:34-39)The backup operation could fail silently. Consider checking the exit status and verifying the backup file was created with proper error messages. Potential Bugs4. Missing container name constant (scripts/run/engine-postgres.sh:14) - CRITICALThe script references CONTAINER_NAME on line 14 but this variable is not defined in the script. It should be added after REPO_ROOT definition. 5. Docker volume inspect edge case (scripts/run/nuke-postgres.sh:11)The volume name extraction could return multiple values if there are multiple mounts to /var/lib/postgresql/data. Adding head -1 would make it more robust. Security Concerns6. Hardcoded credentials (scripts/run/restore-postgres.sh:49)The postgres password is hardcoded as postgres. While this is for local development, consider adding a comment noting this is for dev only. 7. Path injection (all scripts)Using user-provided paths directly in docker commands could be risky. Consider adding path validation to reject dangerous characters. Overall AssessmentVerdict: Approve with suggestions This is a useful addition for developer productivity. The code is generally well-written and follows existing patterns. The main concerns are:
Action ItemsMust fix before merge:
Recommended:
Nice to have:
|
0ffdb8b to
f0c5e79
Compare
be4b98e to
a96fe27
Compare
Code ReviewThank you for adding these PostgreSQL backup and restore scripts! This is a useful addition for local development. Here's my review: ✅ Strengths
🔍 Code Quality & Best Practicesbackup-postgres.sh (lines 1-41):
restore-postgres.sh (lines 1-56):
nuke-postgres.sh (lines 1-33):
engine-postgres.sh (changes):
🐛 Potential BugsCritical issue in restore-postgres.sh (line 51): Suggested fix: Either:
Minor issue in backup-postgres.sh (line 20): 🔒 Security Concerns
⚡ Performance Considerations
🧪 Test Coverage
📝 Additional Recommendations
Example Usage DocumentationConsider adding to the PR description or a doc file: # Backup current postgres state
./scripts/run/backup-postgres.sh /tmp/my-backup.tar.gz
# Nuke existing postgres
./scripts/run/nuke-postgres.sh
# Restore from backup
./scripts/run/restore-postgres.sh /tmp/my-backup.tar.gzSummaryOverall, this is a solid addition that improves the development workflow. The main issue to address is the volume naming inconsistency between postgres.sh and restore-postgres.sh. The other items are minor improvements or considerations. Recommendation: Address the volume naming issue, then this should be good to merge! 👍 |
PR ReviewThank you for adding these helpful development scripts! Overall, this is a solid addition that will make it easier for developers to manage their local Postgres instances. Here's my detailed feedback: ✅ Strengths
🐛 Potential Issues1. Volume persistence issue in
|
a96fe27 to
0d3238b
Compare
PR Review: PostgreSQL Backup & Restore ScriptsOverall, this is a solid addition that provides useful development tooling for managing PostgreSQL data. The scripts are well-structured and follow good bash practices. Below are my findings: ✅ Strengths
🔍 Issues & ConcernsCritical: Data Loss Risk in restore-postgres.shLocation: The restore script stops and removes the existing container without warning the user about potential data loss. This is dangerous for a development workflow. Recommendation: Add a confirmation prompt before destroying existing data Bug: Volume Not Persisted in postgres.shLocation: The Recommendation: Add a named volume to Enhancement: Container State Check in backup-postgres.shLocation: The backup script checks if the container exists but doesn't verify it's running. A stopped container could still have a valid volume to backup, so this check might be too restrictive. Minor: Biome.json FixLocation: Good catch fixing the missing comma - this was a syntax error. Security: Hardcoded CredentialsLocation: Multiple files (postgres.sh, restore-postgres.sh) The scripts use hardcoded credentials ( 📝 Style & Best Practices
🧪 Testing RecommendationsConsider testing these scenarios:
🎯 SummaryApprove with Changes Required The scripts provide valuable functionality but need the following critical fixes:
The enhancement to |
More templates
@rivetkit/actor
@rivetkit/cloudflare-workers
@rivetkit/core
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |
f0c5e79 to
e786fc1
Compare
0d3238b to
00e258e
Compare
PR Review: PostgreSQL Backup & Restore ScriptsSummaryThis PR adds development utilities for PostgreSQL container management including backup, restore, and nuke functionality, plus auto-start capability in engine-postgres.sh. Overall the implementation is solid and follows good bash practices. Code Quality & Best PracticesStrengths:
Minor Issues:
Potential Issues1. Race condition in restore script (scripts/run/restore-postgres.sh:45-53)The script creates and starts the postgres container but doesn't wait for postgres to be ready before reporting success. Consider adding a readiness check similar to the one in engine-postgres.sh. 2. Volume persistence in postgres.sh (scripts/run/postgres.sh:14-21)The existing postgres.sh doesn't specify a named volume, which means Docker will create an anonymous volume. The restore script creates a named volume, but the standard postgres startup doesn't. Consider using a named volume for consistency. 3. Backup script doesn't check if postgres is running (scripts/run/backup-postgres.sh:15-18)The script only checks if the container exists, not if it's running. Backing up while postgres is actively writing could lead to inconsistent backups. Consider adding a warning or check. Security Considerations
Performance Considerations
Additional Recommendations
VerdictStatus: Approve with minor suggestions The core functionality is well-implemented and follows good practices. The suggested improvements are mostly about edge cases and enhanced safety, not critical bugs. The scripts will work well for their intended development use case. The changes to engine-postgres.sh are particularly nice - auto-starting postgres when needed is a great developer experience improvement! |
Code ReviewOverviewThis PR adds three new development scripts for managing PostgreSQL backup/restore operations and improves the engine-postgres.sh script to auto-start postgres. Overall, this is a solid addition for development workflow, but there are several improvements to consider. Critical Issues1. Data Loss Risk in restore-postgres.sh (Lines 20-27) The restore script automatically stops and removes the existing container without confirmation. This could lead to accidental data loss if a developer runs the wrong command. Recommendation: Add a confirmation prompt or at minimum a warning message before destructing the existing container. 2. Security: Hardcoded Credentials (restore-postgres.sh:49-51) Hardcoded postgres credentials (postgres/postgres) are exposed in the script. While this is for dev purposes, it is a pattern that could accidentally propagate to production configs. Recommendation: Consider using environment variables with defaults. Bugs and Issues3. Race Condition in restore-postgres.sh (Line 44-56) The script starts the postgres container immediately after restoring data, but does not verify the container actually started successfully or wait for postgres to be ready. This could cause subsequent operations to fail. Recommendation: Add health check similar to what is in engine-postgres.sh:18-28 4. Error Handling: Silent Failures (nuke-postgres.sh:29) The script uses || true when removing the volume, which masks actual errors that might be important (e.g., volume in use by another container). Recommendation: Capture and display the error, or at least log why the removal failed. 5. Incomplete Validation in backup-postgres.sh (Line 15-17) The script checks if the container exists but does not check if it is running. Backing up a stopped container might result in inconsistent data. Recommendation: Add a check to ensure the container is running or warn the user. Code Quality and Best Practices6. Inconsistent Error Message Style Error messages use different formatting across scripts. Use consistent formatting (lowercase error:, no trailing periods) across all scripts. 7. Missing Dependency Check All scripts assume docker is available but do not verify. The engine-postgres.sh checks for nc (line 7), but new scripts do not check for docker. Recommendation: Add docker availability check at the top of each script. 8. Path Handling Edge Case (backup-postgres.sh:12) Using the first argument directly without validation could cause issues with paths containing special characters or spaces. Already quoted properly, but consider validating the path does not contain newlines or other problematic characters. Performance Considerations9. Backup Performance: Missing Compression Options The backup uses default tar compression (czf) which is gzip. For large databases, this could be slow. Consider adding an optional compression method argument or document expected backup times for large datasets. 10. Volume Creation Strategy (restore-postgres.sh:31) Creates an anonymous volume that may be harder to manage/debug later. Consider creating a named volume for better tracking. Minor Issues and Suggestions11. biome.json Fix (Line 11) Good catch fixing the missing comma! This was a syntax error. 12. pnpm-lock.yaml Changes These appear to be from a merge/rebase from the base branch. Verify these are intentional. 13. Documentation Consider adding a README or comments in CLAUDE.md explaining when to use each script: When to backup vs. restore, What nuke-postgres does (destructive!), Example workflows 14. engine-postgres.sh Enhancement is Good The auto-start functionality (lines 12-28) is a nice UX improvement. However, it references postgres.sh which should be checked into the repo. Test CoverageScripts have basic error handling but no automated tests, no validation of backup file integrity, and no test for restore correctness. Recommendation: Consider adding a simple test script that starts postgres, inserts test data, backs up, nukes, restores, and verifies test data exists. Security AssessmentHardcoded credentials (dev only, but still a pattern concern). No injection vulnerabilities detected (good use of quoting). Appropriate use of set -euo pipefail. No backup encryption (consider for sensitive dev data). SummaryApproval Status: Approve with recommendations This PR adds valuable development tooling. The scripts are well-structured and follow bash best practices (set -euo pipefail, proper quoting). However, implementing the safety checks (especially the confirmation prompt in restore) would prevent potential foot-guns. Priority Fixes:
Nice to Have:
Great work on improving the developer experience! |
00e258e to
21324dd
Compare
Code ReviewThis PR adds useful PostgreSQL backup/restore scripts for local development. Overall the implementation is solid, but I have identified several issues that should be addressed before merging. Critical Issues1. Data Loss Risk in backup-postgres.sh (scripts/run/backup-postgres.sh:35-39)The backup script does not stop the container before backing up, which can lead to corrupted/inconsistent backups if transactions are in progress. PostgreSQL should be stopped or you should use pg_dump instead of raw file copying. Recommendation: Either stop the container before backup, or better yet, use pg_dump for consistent backups. 2. Volume Persistence Issue in restore-postgres.sh (scripts/run/restore-postgres.sh:31)The restore script creates an anonymous volume with docker volume create, but the original postgres.sh does not use named volumes at all. After restore, the next run of postgres.sh will create a fresh container without the restored data. Recommendation: Update postgres.sh to use the same named volume approach, or modify restore-postgres.sh to match postgres.sh behavior. 3. Dangerous Destructive Operation Without ConfirmationBoth nuke-postgres.sh and restore-postgres.sh destroy data without asking for confirmation. This is risky for a development script. Recommendation: Add confirmation prompts before destructive operations. Minor Issues4. Inconsistent Volume Management (scripts/run/backup-postgres.sh:21)The backup script assumes the container uses a named volume, but postgres.sh does not create one. This will cause backup to fail. 5. Missing Error Handling in restore-postgres.sh (scripts/run/restore-postgres.sh:41)The tar extraction does not check if it succeeded before starting the container. If the backup file is corrupted, you will get a container with partial/invalid data. 6. No Health Check After Restore (scripts/run/restore-postgres.sh:55-56)The restore script does not wait for postgres to be ready after starting the container, unlike engine-postgres.sh which does wait. 7. Hardcoded Credentials (scripts/run/restore-postgres.sh:49-51)While this is a dev script, the hardcoded credentials should match any configuration the project uses. Positive Aspects
Test CoverageThese scripts lack any automated tests. While shell scripts are hard to test, consider adding integration tests or at minimum, document manual testing steps in the PR description. Security ConcernsFor development scripts these are acceptable, but note:
Recommendations SummaryMust Fix:
Should Fix: Nice to Have: |

No description provided.