wheels db schema
Export and import database schema definitions.
Synopsis
Description
The db schema
command provides tools for exporting database schemas to files and importing them back. This is useful for version control, documentation, sharing database structures, and setting up new environments.
Subcommands
export
export
Export database schema to a file
import
import
Import database schema from a file
diff
diff
Compare two schema files or database states
validate
validate
Validate a schema file without importing
Global Options
--env
--env
Type: String
Default:
development
Description: The environment to work with
--datasource
--datasource
Type: String
Default: Application default
Description: Specific datasource to use
--format
--format
Type: String
Default:
sql
Options:
sql
,json
,xml
,cfm
Description: Output format for schema
Export Command
Synopsis
Options
--output
--output
Type: String
Default:
db/schema.sql
Description: Output file path
--tables
--tables
Type: String
Default: All tables
Description: Comma-separated list of tables to export
--no-data
--no-data
Type: Boolean
Default:
true
Description: Export structure only, no data
--include-drops
--include-drops
Type: Boolean
Default:
false
Description: Include DROP statements
--include-indexes
--include-indexes
Type: Boolean
Default:
true
Description: Include index definitions
--include-constraints
--include-constraints
Type: Boolean
Default:
true
Description: Include foreign key constraints
Examples
Import Command
Synopsis
Options
--input
--input
Type: String
Default:
db/schema.sql
Description: Input file path
--dry-run
--dry-run
Type: Boolean
Default:
false
Description: Preview import without executing
--force
--force
Type: Boolean
Default:
false
Description: Drop existing objects before import
--skip-errors
--skip-errors
Type: Boolean
Default:
false
Description: Continue on errors
Examples
Diff Command
Synopsis
Options
--output
--output
Type: String
Default: Console output
Description: Save diff to file
--format
--format
Type: String
Default:
text
Options:
text
,sql
,html
Description: Diff output format
Examples
Use Cases
Version Control
Track schema changes in git:
Environment Setup
Set up new developer environment:
Database Documentation
Generate schema documentation:
Continuous Integration
Validate schema in CI:
Backup and Recovery
Create schema backups:
Schema File Formats
SQL Format (Default)
JSON Format
CFM Format
Best Practices
1. Regular Exports
Export schema after each migration:
2. Environment Comparison
Regularly compare environments:
3. Schema Validation
Validate before deployment:
4. Backup Strategy
Maintain schema history:
Integration with Migrations
Schema vs Migrations
Migrations: Incremental changes
Schema: Current state snapshot
Workflow
Run migrations:
wheels dbmigrate latest
Export schema:
wheels db schema export
Commit both:
git add db/migrate/* db/schema.sql
Notes
Schema export captures current database state
Some database-specific features may not export perfectly
Always review exported schemas before importing
Use migrations for incremental changes, schemas for full setup
Related Commands
Last updated
Was this helpful?