CLI Commands

Complete guide to Akron CLI commands for database management, migrations, and development workflow.

Overview

The Akron CLI provides powerful command-line tools for database management, schema migrations, data seeding, and development workflows. Akron now supports both modern schema management commands and legacy database operation commands.

NEW

Modern Schema Management

Akron features powerful declarative schema management:

akron db init --provider sqlite

Installation

The CLI is automatically installed with the Akron package:

pip install akron

Modern Schema Management Commands

These commands provide a modern workflow for managing your database schema declaratively.

akron db init

Initialize a new Akron project with schema configuration file.

akron db init --provider sqlite

akron db makemigrations

Generate migration files from schema changes automatically.

akron db makemigrations --name "initial"

akron db migrate

Apply pending migrations to update your database schema.

akron db migrate --dry-run

akron db status

Show current schema and migration status information.

akron db status

Legacy Commands

These commands provide direct database operations and are maintained for backward compatibility.

Common Patterns

Database Connection URLs

All CLI commands use the --db parameter to specify database connections:

Connection URL Examples
1# SQLite (file-based)
2akron create-table users --db "sqlite:///./myapp.db" --schema '{"id": "int", "name": "str"}'
3
4# SQLite (in-memory)
5akron create-table users --db "sqlite:///:memory:" --schema '{"id": "int", "name": "str"}'
6
7# MySQL
8akron create-table users --db "mysql://user:password@localhost:3306/mydb" --schema '{"id": "int", "name": "str"}'
9
10# PostgreSQL
11akron create-table users --db "postgres://user:password@localhost:5432/mydb" --schema '{"id": "int", "name": "str"}'
12
13# MongoDB
14akron create-table users --db "mongodb://localhost:27017/mydb" --schema '{"id": "int", "name": "str"}'

Schema Definition Format

Schema definitions use JSON format with Akron type mapping:

Schema JSON Format
1# Basic types
2--schema '{"id": "int", "name": "str", "price": "float", "active": "bool"}'
3
4# Foreign key relationships
5--schema '{"id": "int", "user_id": "int->users.id", "title": "str", "content": "str"}'
6
7# Complex example with multiple relationships
8--schema '{
9 "id": "int",
10 "customer_id": "int->customers.id",
11 "product_id": "int->products.id",
12 "quantity": "int",
13 "price": "float",
14 "order_date": "str"
15}'

Development Workflow

Typical development workflow using Akron CLI:

Complete Development Workflow
1# 1. Create initial schema
2akron create-table users --db "sqlite:///app.db" --schema '{"id": "int", "username": "str", "email": "str"}'
3
4# 2. Add related tables
5akron create-table posts --db "sqlite:///app.db" --schema '{"id": "int", "user_id": "int->users.id", "title": "str", "content": "str"}'
6
7# 3. Inspect current schema
8akron inspect-schema --db "sqlite:///app.db"
9
10# 4. Seed with test data
11akron seed users --db "sqlite:///app.db" --data '[{"username": "alice", "email": "alice@example.com"}]'
12
13# 5. Generate migration for schema changes
14akron makemigrations users --db "sqlite:///app.db" --schema '{"id": "int", "username": "str", "email": "str", "created_date": "str"}'
15
16# 6. Apply migrations
17akron migrate --db "sqlite:///app.db"
18
19# 7. Execute custom queries
20akron raw-sql --db "sqlite:///app.db" --query "SELECT COUNT(*) FROM users WHERE email LIKE '%@example.com'"
21
22# 8. Drop tables when cleaning up
23akron drop-table test_table --db "sqlite:///app.db"

Global Options

--db (required)

Database connection URL. Must be provided for all commands except --help and --version.

akron command --db "sqlite:///database.db"

--help

Display help information for any command.

akron create-table --help

--version

Show the installed Akron version.

akron --version

Quick Examples

Essential CLI Commands
1# Quick setup: Create a users table
2akron create-table users --db "sqlite:///quickstart.db" --schema '{"id": "int", "name": "str", "email": "str"}'
3
4# Add some test data
5akron seed users --db "sqlite:///quickstart.db" --data '[
6 {"name": "Alice", "email": "alice@example.com"},
7 {"name": "Bob", "email": "bob@example.com"}
8]'
9
10# Check what's in the database
11akron inspect-schema --db "sqlite:///quickstart.db"
12
13# Run a custom query
14akron raw-sql --db "sqlite:///quickstart.db" --query "SELECT * FROM users"
15
16# Clean up
17akron drop-table users --db "sqlite:///quickstart.db"
Expected Output
✓ Table 'users' created successfully
✓ Seeded 2 records into 'users' table

Database Schema:
├── users
│   ├── id (int)
│   ├── name (str)
│   └── email (str)

Query Results:
[
  {"id": 1, "name": "Alice", "email": "alice@example.com"},
  {"id": 2, "name": "Bob", "email": "bob@example.com"}
]

✓ Table 'users' dropped successfully

Next Steps

Explore specific CLI commands for detailed usage:

Schema Commands

Create and manage database tables

→ view create-table command

Migration System

Version control for database schemas

→ view migration commands

Python API

Use Akron programmatically in your code

→ view Python API docs