fix: honor --dry-run flag in migration commands (fixes #133) #135
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
Fixes the critical data safety bug where the
--dry-runflag was accepted but completely ignored, causing migrations to actually modify the database when users expected no changes to occur.Closes #133
Problem
The
--dry-runflag was defined in the CLI commands but never passed through to the migration execution functions. This meant that:sqlspec upgrade --dry-runwould have their database actually modifiedsqlspec downgrade --dry-runwould have migrations actually revertedThis is a critical data safety issue.
Solution
Changes Made
Migration Commands (sqlspec/migrations/commands.py)
dry_run: bool = Falseparameter toupgrade()anddowngrade()methodsdry_run=True:runner.execute_upgrade()/runner.execute_downgrade()tracker.record_migration()/tracker.remove_migration()SyncMigrationCommandsandAsyncMigrationCommandsCLI Commands (sqlspec/cli.py)
dry_run=dry_runparameter:Example Output
Before (BUG):
```
$ sqlspec downgrade --dry-run
Are you sure you want to downgrade the database to the
-1revision? [y/n]: yReverting 1 migrations
Reverting 0002: oauth
✓ Reverted in 12ms
$ sqlspec show-current-revision
Current version: 0001 # DATABASE WAS MODIFIED!
```
After (FIXED):
```
$ sqlspec downgrade --dry-run
DRY RUN MODE: No database changes will be applied
Are you sure you want to downgrade the database to the
-1revision? [y/n]: yReverting 1 migrations
Would revert 0002: oauth
Migration file: /path/to/migrations/0002_oauth.sql
Dry run complete. No changes were made to the database.
$ sqlspec show-current-revision
Current version: 0002 # DATABASE UNCHANGED
```
Checklist