Skip to content

Conversation

kazuooooo
Copy link

@kazuooooo kazuooooo commented Jul 25, 2025

Summary

  • Add stronger warnings and interactive confirmation when DROP statements are detected in schema diffs
  • Add --confirm-drops option to control drop warning behavior
  • Helps prevent accidental data loss from column renames being detected as DROP+ADD operations

Motivation

Currently, supabase db diff shows a weak warning when DROP statements are detected. This is particularly problematic for column renames, which are detected as DROP COLUMN + ADD COLUMN operations, potentially causing data loss.

Changes

  • Show clear danger warning with red highlighting and visual separator
  • List all detected DROP statements with red arrows
  • Explain specific risks including:
    • Column renames being detected as DROP + ADD
    • Permanent data loss from table/schema deletions
    • Suggestion to use RENAME operations instead
  • Require user confirmation with default "No" for safety
  • Operation is cancelled if user declines
  • NEW: Add --confirm-drops option with three modes:
    • prompt (default): Show interactive confirmation prompt
    • skip: Bypass confirmation and proceed automatically
    • deny: Always refuse operations with DROP statements

Test plan

  • Added unit tests for the new showDropWarningAndConfirm function
  • Added unit tests for --confirm-drops option handling
  • Manual testing with actual DROP operations
  • Manual testing with column rename scenarios
  • Manual testing with all --confirm-drops modes

Example 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]

New option usage

# Default behavior (show prompt)
supabase db diff

# Skip confirmation and proceed automatically
supabase db diff --confirm-drops=skip

# Always deny DROP operations
supabase db diff --confirm-drops=deny

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@kazuooooo kazuooooo requested a review from a team as a code owner July 25, 2025 09:22
@kazuooooo kazuooooo closed this Jul 25, 2025
@kazuooooo
Copy link
Author

Sorry, I'm cheking by myself, and reopen.

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