Command Line Tools
dbmigrate remove table
dbmigrate remove table
Section titled “dbmigrate remove table”Generate a migration file for dropping a database table.
Synopsis
Section titled “Synopsis”wheels dbmigrate remove table name=<table_name>Alias: wheels db remove table
CommandBox Parameter Syntax
Section titled “CommandBox Parameter Syntax”This command supports multiple parameter formats:
- Named parameters:
name=value(e.g.,name=users) - Flag parameters:
--flag=value(e.g.,--name=users)
Parameter Mixing Rules:
ALLOWED:
- Named:
wheels dbmigrate remove table name=users - Flag:
wheels dbmigrate remove table --name=users
NOT ALLOWED:
- Positional parameters: This command does not support positional parameters
Recommendation: Use named parameters: wheels dbmigrate remove table name=users
Description
Section titled “Description”The dbmigrate remove table command generates a migration file that drops an existing database table. The generated migration includes a dropTable() call in the up() method.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | The name of the table to remove |
Examples
Section titled “Examples”Basic table removal
Section titled “Basic table removal”wheels dbmigrate remove table name=temp_import_dataRemove user table
Section titled “Remove user table”wheels dbmigrate remove table name=userRemove archive table
Section titled “Remove archive table”wheels dbmigrate remove table name=orders_archive_2023Generated Migration Example
Section titled “Generated Migration Example”For the command:
wheels dbmigrate remove table name=product_archiveGenerates:
component extends="wheels.migrator.Migration" hint="remove product_archive table" {
function up() { transaction { dropTable("product_archive"); } }
function down() { transaction { // Add code here to recreate the table if needed for rollback // createTable(name="product_archive") { ... } } }
}Use Cases
Section titled “Use Cases”Removing Temporary Tables
Section titled “Removing Temporary Tables”Clean up temporary or staging tables:
# Remove import staging tablewheels dbmigrate remove table name=temp_customer_import
# Remove data migration tablewheels dbmigrate remove table name=migration_backup_20240115Refactoring Database Schema
Section titled “Refactoring Database Schema”Remove tables during schema refactoring:
# Remove old table after data migrationwheels dbmigrate remove table name=legacy_orders
# Remove deprecated tablewheels dbmigrate remove table name=user_preferences_oldCleaning Up Failed Features
Section titled “Cleaning Up Failed Features”Remove tables from cancelled features:
# Remove tables from abandoned featurewheels dbmigrate remove table name=beta_feature_datawheels dbmigrate remove table name=beta_feature_settingsArchive Table Cleanup
Section titled “Archive Table Cleanup”Remove old archive tables:
# Remove yearly archive tableswheels dbmigrate remove table name=orders_archive_2020wheels dbmigrate remove table name=orders_archive_2021Safety Considerations
Section titled “Safety Considerations”Data Loss Warning
Section titled “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
Section titled “Dependent Objects”Consider objects that depend on the table:
- Foreign key constraints
- Views
- Stored procedures
- Triggers
- Application code
Handling Dependencies
Section titled “Handling Dependencies”Be aware of dependent objects when removing tables:
- Foreign key constraints
- Views that reference the table
- Stored procedures using the table
- Application code dependencies
Best Practices
Section titled “Best Practices”1. Document Removals
Section titled “1. Document Removals”Add clear documentation about why the table is being removed:
# Create descriptive migrationwheels dbmigrate remove table name=obsolete_analytics_cache
# Then edit the migration file to add detailed comments about why it's being removed2. Backup Data First
Section titled “2. Backup Data First”Before removing tables, create data backups:
# First backup the datawheels db schema format=sql > backup_before_removal.sql
# Then create removal migrationwheels dbmigrate remove table name=user_preferences3. Staged Removal
Section titled “3. Staged Removal”For production systems, consider staged removal:
# Stage 1: Rename table (keep for rollback)wheels dbmigrate create blank name=rename_orders_to_orders_deprecated
# Stage 2: After verification period, removewheels dbmigrate remove table name=orders_deprecated4. Check Dependencies
Section titled “4. Check Dependencies”Verify no active dependencies before removal:
-- Check foreign keysSELECT * FROM information_schema.referential_constraintsWHERE referenced_table_name = 'table_name';
-- Check viewsSELECT * FROM information_schema.viewsWHERE table_schema = DATABASE()AND view_definition LIKE '%table_name%';Migration Structure
Section titled “Migration Structure”The generated migration contains:
- An
up()method withdropTable() - An empty
down()method for you to implement rollback logic if needed
You should edit the down() method to add table recreation logic if you want the migration to be reversible.
Recovery Strategies
Section titled “Recovery Strategies”If Removal Was Mistake
Section titled “If Removal Was Mistake”- Don’t run the migration in production
- Use
wheels dbmigrate downif already run - Restore from backup if down() fails
Preserving Table Structure
Section titled “Preserving Table Structure”Before removal, capture structure:
# Export entire database schemawheels db schema format=sql --save file=schema_backup.sql
# Then remove tablewheels dbmigrate remove table name=user_preferences- 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
Section titled “Related Commands”wheels dbmigrate create table- Create tableswheels dbmigrate create blank- Create custom migrationswheels dbmigrate up- Run migrationswheels dbmigrate down- Rollback migrationswheels db schema- Export table schemas