Database Management Overview
The Wheels CLI provides comprehensive database management commands that make it easy to create, manage, and maintain your application's database throughout the development lifecycle.
Overview
Database management in Wheels is divided into two main categories:
Database Commands (
wheels db
) - High-level database operationsMigration Commands (
wheels dbmigrate
) - Schema versioning and changes
This guide covers the database management commands. For migration-specific operations, see the migrations guide.
Database Lifecycle Commands
Creating a Database
The wheels db create
command creates a new database based on your datasource configuration:
Note: The datasource must already be configured in your CFML server admin. The command will create the database itself but not the datasource configuration.
Dropping a Database
The wheels db drop
command removes an existing database:
Warning: This is a destructive operation. Always backup important data before dropping a database.
Database Setup
The wheels db setup
command performs a complete database initialization:
This is ideal for setting up a new development environment or initializing a test database.
Database Reset
The wheels db reset
command completely rebuilds your database:
Important: This command will destroy all existing data. Use with caution, especially in production environments.
Data Management
Seeding the Database
The wheels db seed
command populates your database with test or sample data:
Example seed data file format:
Status and Information Commands
Checking Migration Status
The wheels db status
command shows the current state of your migrations:
Output example:
Checking Database Version
The wheels db version
command shows the current schema version:
Migration Management
Rolling Back Migrations
The wheels db rollback
command reverses previously applied migrations:
Backup and Restore
Creating Database Backups
The wheels db dump
command exports your database:
Restoring from Backups
The wheels db restore
command imports a database dump:
Common Workflows
Setting Up a New Development Environment
Resetting Development Database
Production Database Backup
Migrating Between Environments
Interactive Database Shell
The wheels db shell
command provides direct access to your database's interactive shell:
Database-Specific Shells
H2 Database:
MySQL:
PostgreSQL:
SQL Server:
Shell Requirements
The database shell commands require the appropriate database client tools to be installed:
H2: No additional installation needed (included with Lucee)
MySQL: Install
mysql
clientPostgreSQL: Install
psql
clientSQL Server: Install
sqlcmd
client
Database Support
The database commands support multiple database engines:
MySQL/MariaDB - Full support for all operations
PostgreSQL - Full support for all operations
SQL Server - Full support for most operations
H2 - Full support (auto-created databases)
Oracle - Limited support (basic operations)
Configuration
Database commands use the datasource configuration from your Wheels application. You can override settings using command parameters:
Safety Features
Confirmation Prompts - Destructive operations require confirmation
Force Flag - Use
--force
to skip confirmations in scriptsEnvironment Detection - Extra warnings for production environments
Transaction Support - Operations are wrapped in transactions where possible
Troubleshooting
Common Issues
Datasource Not Found
Solution: Create the datasource in your CFML server admin first.
Database Already Exists
Solution: Use wheels db drop
first or use wheels db reset
instead.
Permission Denied
Solution: Ensure the database user has CREATE/DROP privileges.
Missing Database Tools
Solution: Install database client tools for dump/restore operations.
Best Practices
Always backup before destructive operations
Use environment-specific datasources
myapp_dev
for developmentmyapp_test
for testingmyapp_prod
for production
Automate with scripts
Version control your seeds
Keep seed files in
db/seeds/
Use environment-specific seed files
Document seed data structure
Related Commands
wheels dbmigrate
- Database migration commandswheels test
- Test database operationswheels generate model
- Generate models with migrations
Last updated
Was this helpful?