Database Commands

Azu CLI provides database management commands that work with CQL ORM.

Command Overview

Command
Description

azu db:create

Create the database

azu db:drop

Drop the database

azu db:migrate

Run pending migrations

azu db:rollback

Rollback migrations

azu db:reset

Drop, create, and migrate

azu db:setup

Create and migrate

azu db:seed

Run seed data

azu db:status

Show migration status

Configuration

Environment Variables

# Using DATABASE_URL (recommended)
export DATABASE_URL="postgresql://user:pass@localhost/myapp_dev"

# Or individual variables
export AZU_DB_HOST="localhost"
export AZU_DB_PORT="5432"
export AZU_DB_NAME="myapp_dev"
export AZU_DB_USER="username"
export AZU_DB_PASSWORD="password"

azu db:create

Creates the database for the current environment.

azu db:drop

Drops the database for the current environment.

azu db:migrate

Runs pending migrations using CQL's Migrator. Automatically updates src/db/schema.cr.

Migration File Format

Column Types

Method
Crystal Type
Description

primary

Int64/UUID

Primary key

text

String

Text field

integer

Int32

32-bit integer

bigint

Int64

64-bit integer

boolean

Bool

Boolean value

decimal

Float64

Decimal number

timestamps

Time

created/updated_at

azu db:rollback

Rolls back migrations. Automatically updates the schema file.

azu db:reset

Drops, creates, and migrates the database.

azu db:setup

Creates the database (if needed) and runs migrations.

azu db:seed

Runs seed data from src/db/seed.cr.

Seed File Example

azu db:status

Shows migration status.

Output:

azu generate migration

Creates a new migration file.

Add Column Migration

Add Index Migration

Common Workflows

Development

Testing

Production

Troubleshooting

Connection Issues

Permission Issues

Migration Issues


Next Steps:

Last updated