wheels db schema
Visualize the current database schema.
Synopsis
Description
The wheels db schema
command retrieves and displays the current database schema in various formats. This is useful for documentation, debugging, and understanding your database structure.
Parameters
format
string
No
"sql"
Output format (text, json, or sql)
--save
boolean
No
false
Save output to file instead of console
file
string
No
-
File path to write schema to (when using --save)
engine
string
No
"default"
Database engine to use
Examples
Display schema in console (default SQL format)
Display schema as text
Export schema to file
Export as JSON
Output Formats
Text Format
Displays a human-readable table structure:
SQL Format (Default)
Generates CREATE TABLE statements:
JSON Format
Provides structured schema information:
Use Cases
Version Control
Track schema changes in git:
Documentation
Generate schema documentation:
Backup Before Changes
Create schema backups before major updates:
Review Database Structure
Quickly review your database structure:
Notes on Table Filtering
Currently, the command exports all tables in the database. Future versions may support filtering specific tables.
Best Practices
1. Regular Exports
Export schema after migrations:
2. Use Version Control
Track schema changes over time:
3. Document Changes
Keep a record of schema state:
Integration with Migrations
Schema vs Migrations
Migrations: Track incremental changes over time
Schema: Shows current database state
Typical Workflow
Create migration:
wheels dbmigrate create table name=users
Edit and run migration:
wheels dbmigrate up
Export current schema:
wheels db schema --save file=db/schema.sql
Commit both:
git add app/migrator/migrations/* db/schema.sql
Notes
Schema export captures current database state
The command connects to your configured datasource
Output varies based on your database type (MySQL, PostgreSQL, etc.)
Some database-specific features may require manual adjustment
Use migrations for incremental changes, schemas for documentation
Related Commands
wheels dbmigrate latest
- Run all migrationswheels dbmigrate info
- View migration statuswheels db seed
- Seed database with datawheels generate model
- Generate models from schema
Last updated
Was this helpful?