wheels dbmigrate remove table
Generate a migration file for dropping a database table.
Synopsis
Description
The dbmigrate remove table
command generates a migration file that drops an existing database table. The generated migration includes both the drop operation and a reversible up method that recreates the table structure, making the migration fully reversible.
Arguments
<table_name>
<table_name>
Type: String
Required: Yes
Description: The name of the table to drop
Options
--datasource
--datasource
Type: String
Default: Application default
Description: Target datasource for the migration
--force
--force
Type: Boolean
Default:
false
Description: Skip safety prompts and generate migration immediately
--no-backup
--no-backup
Type: Boolean
Default:
false
Description: Don't include table structure backup in the down() method
--cascade
--cascade
Type: Boolean
Default:
false
Description: Include CASCADE option to drop dependent objects
Examples
Basic table removal
Remove table with cascade
Force removal without prompts
Remove without backup structure
Generated Migration Example
For the command:
Generates:
Use Cases
Removing Temporary Tables
Clean up temporary or staging tables:
Refactoring Database Schema
Remove tables during schema refactoring:
Cleaning Up Failed Features
Remove tables from cancelled features:
Archive Table Cleanup
Remove old archive tables:
Safety Considerations
Data Loss Warning
CRITICAL: Dropping a table permanently deletes all data. Always:
Backup the table data before removal
Verify data has been migrated if needed
Test in development/staging first
Have a rollback plan
Dependent Objects
Consider objects that depend on the table:
Foreign key constraints
Views
Stored procedures
Triggers
Application code
Using CASCADE
The --cascade
option drops dependent objects:
Best Practices
1. Document Removals
Add clear documentation about why the table is being removed:
2. Backup Data First
Before removing tables, create data backups:
3. Staged Removal
For production systems, consider staged removal:
4. Check Dependencies
Verify no active dependencies before removal:
Migration Structure Details
With Backup (Default)
The generated down() method includes table structure:
Without Backup
With --no-backup
, down() is simpler:
Recovery Strategies
If Removal Was Mistake
Don't run the migration in production
Use
wheels dbmigrate down
if already runRestore from backup if down() fails
Preserving Table Structure
Before removal, capture structure:
Notes
The command analyzes table structure before generating migration
Foreign key constraints must be removed before table removal
The migration is reversible if table structure is preserved
Always review generated migration before running
Related Commands
Last updated
Was this helpful?