Skip to content

Feat/enhance drop warning #3920

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

kazuooooo
Copy link

@kazuooooo kazuooooo commented Jul 26, 2025

Summary

  • Add --confirm-drops option to control drop warning behavior
  • Default: shows simple warning message for drop statements
  • With --confirm-drops: displays detailed warning and requires user confirmation
  • Helps prevent accidental data loss from column renames being detected as DROP+ADD operations

Motivation

Currently, supabase db diff shows a very weak warning when DROP statements are detected.

Found drop statements in schema diff. Please double check if these are expected:
alter table "public"."map_groups" drop column "import_status"
alter table "public"."map_groups" drop column "memo" 

This is particularly problematic for column renames, which are detected as DROP COLUMN + ADD COLUMN operations, potentially causing data loss. #1721 (comment)
(I actually encountered this issue and it caused a major system failure. I am creating this Pull Request to prevent further victims.)

Changes

  • Add --confirm-drops boolean flag to db diff command
  • Default behavior (no flag): Shows simple warning message for detected DROP statements
  • With --confirm-drops flag: Shows detailed danger warning with:
    • Red highlighting and visual separator
    • List of all detected DROP statements with red arrows
    • Explanation of specific risks including column renames and data loss
    • Interactive confirmation prompt with default "No" for safety
    • Operation cancelled if user declines
  • Applies to both migra and pgadmin diff modes

Test plan

  • Added unit tests for the option handling
  • Manual testing with actual DROP operations
  • Manual testing with column rename scenarios

Example usage

Default behavior (simple warning)

supabase db diff

Output:

Found drop statements in schema diff. Please double check if these are expected:
ALTER TABLE public.users DROP COLUMN old_name
DROP TABLE public.legacy_data

With confirmation prompt

supabase db diff --confirm-drops

Output:

⚠️  DANGEROUS OPERATION DETECTED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The following DROP statements were found in your schema diff:

  ▶ ALTER TABLE public.users DROP COLUMN old_name
  ▶ DROP TABLE public.legacy_data

❗ These operations may cause DATA LOSS:
  • Column renames are detected as DROP + ADD, which will lose existing data
  • Table or schema deletions will permanently remove all data
  • Consider using RENAME operations instead of DROP + ADD for columns

Please review the generated migration file carefully before proceeding.

Do you want to continue with this potentially destructive operation? [y/N]

🤖 Generated with Claude Code

kazuooooo and others added 2 commits July 25, 2025 18:20
Add stronger warnings and interactive confirmation when DROP statements
are detected in schema diffs. This helps prevent accidental data loss
from column renames being detected as DROP+ADD operations.

- Show clear danger warning with red highlighting
- List all detected DROP statements
- Explain risks including column rename issues
- Require user confirmation (default: No)
- Add unit tests for new functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Add optional --confirm-drops flag to db diff command:
- Default behavior: shows simple warning message for drop statements
- With --confirm-drops: displays detailed warning and requires user confirmation
- Applies to both migra and pgadmin diff modes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@kazuooooo kazuooooo requested a review from a team as a code owner July 26, 2025 03:35
kazuooooo and others added 3 commits July 26, 2025 12:43
Fix gofmt formatting issues:
- Align variable declarations in cmd/db.go
- Remove trailing whitespace in diff.go and diff_test.go

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Add documentation for the new --confirm-drops flag in db diff command:
- Explain default behavior vs --confirm-drops behavior
- Include usage examples
- Clarify the importance for preventing data loss from column renames

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Simplify documentation to match existing format:
- Remove separate section
- Add concise one-line explanation inline with other options
- Keep consistent formatting with existing documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant