CLI Overview
Quick Start Guide
wheels info
wheels reload
wheels deps
wheels destroy
wheels watch
wheels generate app
wheels generate app-wizard
wheels generate controller
wheels generate model
wheels generate view
wheels generate property
wheels generate route
wheels generate resource
wheels generate api-resource
wheels generate frontend
wheels generate test
wheels generate snippets
wheels scaffold
wheels db create
wheels db drop
wheels db setup
wheels db reset
wheels db status
wheels db version
wheels db rollback
wheels db seed
wheels db dump
wheels db restore
wheels db shell
wheels db schema
wheels dbmigrate info
wheels dbmigrate latest
wheels dbmigrate up
wheels dbmigrate down
wheels dbmigrate reset
wheels dbmigrate exec
wheels dbmigrate create blank
wheels dbmigrate create table
wheels dbmigrate create column
wheels dbmigrate remove table
wheels test
wheels test run
wheels test coverage
wheels test debug
wheels config list
wheels config set
wheels config env
wheels env
wheels env setup
wheels env list
wheels env switch
wheels environment
wheels console
wheels runner
wheels server
wheels server start
wheels server stop
wheels server restart
wheels server status
wheels server log
wheels server open
wheels plugins
wheels plugins list
wheels plugins install
wheels plugins remove
wheels analyze
wheels analyze code
wheels analyze performance
wheels analyze security
wheels security
wheels security scan
wheels optimize
wheels optimize performance
wheels docs
wheels docs generate
wheels docs serve
wheels ci init
wheels docker init
wheels docker deploy
wheels deploy
wheels deploy audit
wheels deploy exec
wheels deploy hooks
wheels deploy init
wheels deploy lock
wheels deploy logs
wheels deploy proxy
wheels deploy push
wheels deploy rollback
wheels deploy secrets
wheels deploy setup
wheels deploy status
wheels deploy stop
Configuration Management
Creating Commands
Service Architecture
Migrations Guide
Testing Guide
Object Relational Mapping
Creating Records
Reading Records
Updating Records
Deleting Records
Column Statistics
Dynamic Finders
Getting Paginated Data
Associations
Nested Properties
Object Validation
Object Callbacks
Calculated Properties
Transactions
Dirty Records
Soft Delete
Automatic Time Stamps
Using Multiple Data Sources
dbmigrate remove table
Generate a migration file for dropping a database table.
Synopsis
wheels dbmigrate remove table name=<table_name>
Alias: wheels db remove table
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
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| name
| string | Yes | The name of the table to remove |
Examples
Basic table removal
wheels dbmigrate remove table name=temp_import_data
Remove user table
wheels dbmigrate remove table name=user
Remove archive table
wheels dbmigrate remove table name=orders_archive_2023
Generated Migration Example
For the command:
wheels dbmigrate remove table name=product_archive
Generates:
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
Removing Temporary Tables
Clean up temporary or staging tables:
# Remove import staging table
wheels dbmigrate remove table name=temp_customer_import
# Remove data migration table
wheels dbmigrate remove table name=migration_backup_20240115
Refactoring Database Schema
Remove tables during schema refactoring:
# Remove old table after data migration
wheels dbmigrate remove table name=legacy_orders
# Remove deprecated table
wheels dbmigrate remove table name=user_preferences_old
Cleaning Up Failed Features
Remove tables from cancelled features:
# Remove tables from abandoned feature
wheels dbmigrate remove table name=beta_feature_data
wheels dbmigrate remove table name=beta_feature_settings
Archive Table Cleanup
Remove old archive tables:
# Remove yearly archive tables
wheels dbmigrate remove table name=orders_archive_2020
wheels dbmigrate remove table name=orders_archive_2021
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
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
1. Document Removals
Add clear documentation about why the table is being removed:
# Create descriptive migration
wheels dbmigrate remove table name=obsolete_analytics_cache
# Then edit the migration file to add detailed comments about why it's being removed
2. Backup Data First
Before removing tables, create data backups:
# First backup the data
wheels db schema format=sql > backup_before_removal.sql
# Then create removal migration
wheels dbmigrate remove table name=user_preferences
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, remove
wheels dbmigrate remove table name=orders_deprecated
4. Check Dependencies
Verify no active dependencies before removal:
-- Check foreign keys
SELECT * FROM information_schema.referential_constraints
WHERE referenced_table_name = 'table_name';
-- Check views
SELECT * FROM information_schema.views
WHERE table_schema = DATABASE()
AND view_definition LIKE '%table_name%';
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
If Removal Was Mistake
- Don't run the migration in production
- Use
wheels dbmigrate down
if already run - Restore from backup if down() fails
Preserving Table Structure
Before removal, capture structure:
# Export entire database schema
wheels db schema format=sql --save file=schema_backup.sql
# Then remove table
wheels dbmigrate remove table name=user_preferences
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
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
- Synopsis
- Parameters
- Examples
- Basic table removal
- Remove user table
- Remove archive table
- Generated Migration Example
- Use Cases
- Removing Temporary Tables
- Refactoring Database Schema
- Cleaning Up Failed Features
- Archive Table Cleanup
- Safety Considerations
- Data Loss Warning
- Dependent Objects
- Handling Dependencies
- Best Practices
- 1. Document Removals
- 2. Backup Data First
- 3. Staged Removal
- 4. Check Dependencies
- Migration Structure
- Recovery Strategies
- If Removal Was Mistake
- Preserving Table Structure
- Notes
- Related Commands