Database Commands
Azu CLI provides a comprehensive set of database commands for managing your application's database. These commands work with CQL ORM and support PostgreSQL, MySQL, and SQLite.
Overview
All database commands follow the pattern:
azu db:<command> [options]Available Commands
azu db:create
Create the database
azu db:migrate
Run pending migrations
azu db:rollback
Rollback migrations
azu db:reset
Drop, create, and migrate database
azu db:seed
Run seed data
azu db:status
Show migration status
azu db:setup
Setup database (create and migrate)
azu db:drop
Drop the database
Database Configuration
Environment Variables
Configuration File
azu db:create
Creates the database for the current environment.
Basic Usage
Options
--env <environment>
Target environment
development
--database <name>
Database name
auto-detected
--force
Force creation (drop if exists)
false
Examples
Troubleshooting
azu db:reset
Resets the database by dropping, creating, migrating, and optionally seeding.
Basic Usage
Options
--force
Skip confirmation prompt
false
Examples
azu db:migrate
Runs pending database migrations using CQL's built-in Migrator to update the database schema.
Key Features:
Uses CQL's
Migratorclass for type-safe migrationsAutomatically updates
src/db/schema.crafter running migrationsTracks migrations in
cql_schema_migrationstableGenerates temporary Crystal script for execution
Basic Usage
Options
--env <environment>
Target environment
development
--version <version>
Migrate to specific version
latest
--steps <number>
Number of migrations to run
all
--verbose
Show detailed output
false
Examples
How It Works
CLI generates a temporary Crystal script in the project root
Script loads
src/db/schema.crand all migration files fromsrc/db/migrations/CQL Migrator runs pending migrations in order using the generated script
Schema file is automatically synchronized with the database
Migration status is tracked in the
schema_migrationstableTemporary script is cleaned up after execution
Migration File Example
azu db:rollback
Rolls back database migrations using CQL's Migrator. Automatically updates the schema file after rollback.
Basic Usage
Options
--steps <number>
Number of migrations to rollback
1
--version <version>
Rollback to specific version
-
--verbose
Show detailed output
false
Examples
How It Works
CLI generates a temporary Crystal script in the project root
Script loads
src/db/schema.crand all migration files fromsrc/db/migrations/CQL Migrator executes the
downmethod for each migration in reverse orderRemoves migration records from
schema_migrationstableSchema file is automatically synchronized with the database
Temporary script is cleaned up after execution
azu db:reset
Drops, creates, and migrates the database in one command.
Basic Usage
Options
--seed
Run seed data after reset
false
--force
Skip confirmation prompt
false
Examples
azu db:setup
Sets up the database by creating it (if it doesn't exist) and running all migrations.
Basic Usage
Options
--seed
Run seed data after setup
false
Examples
azu db:drop
Drops the database for the current environment.
Basic Usage
Options
--force
Skip confirmation prompt
false
Examples
azu db:seed
Runs seed data to populate the database with initial data.
Basic Usage
Examples
Seed File Structure
azu generate migration
Creates a new CQL migration file with proper Schema DSL syntax.
Basic Usage
Examples
Supported Attribute Types
string,text→Stringint32,integer→Int32int64→Int64float,float64→Float64bool,boolean→Booldatetime,time→Timedate→Datejson→JSON::Anyuuid→UUIDreferences,belongs_to→ Foreign key (Int64)
azu db:status
Shows the current migration status.
Basic Usage
Examples
Database Adapters
PostgreSQL
MySQL
SQLite
Common Workflows
Development Workflow
Testing Workflow
Production Workflow
Troubleshooting
Connection Issues
Permission Issues
Migration Issues
Seed Issues
Best Practices
1. Environment Management
2. Migration Safety
3. Seed Data
4. Database URLs
The database commands provide a complete workflow for managing your Azu application's database, from creation to migration to seeding.
Next Steps:
Migration Generator - Create database migrations
Model Generator - Create database models
Development Workflows - Learn database workflows
Last updated