AuthKit CLI
A CLI tool for AuthKit database schema management with feature-based migrations.
Overview
AuthKit CLI is a companion tool for the AuthKit authentication library. It provides a feature-based approach to database schema management, similar to better-auth:
- Feature detection - Configure which features you need in
authkit.toml - Single migration per feature - Clean, consolidated migrations instead of many small files
- Migration generation - Generate SQL migration files for SQLite and PostgreSQL
- Migration execution - Apply pending migrations to your database
- Status checking - View which migrations have been applied
- Schema visualization - Display the current schema in various formats
Installation
From crates.io
From source
Quick Start
# 1. Initialize configuration
# 2. Edit authkit.toml to enable features you need
# 3. Generate migrations
# 4. Apply migrations to your database
# 5. Check migration status
Configuration
AuthKit CLI uses authkit.toml to define which features are enabled:
[]
= "postgres" # or "sqlite"
[]
= true # Base feature (always enabled)
= true # Adds email verification support
Available Features
| Feature | Description | Tables/Changes |
|---|---|---|
email_password |
Base authentication (required) | users, accounts, sessions, verification |
email_verification |
Email verification support | Adds email_verified, email_verified_at to users |
More features coming soon: OAuth, magic links, two-factor authentication, etc.
Commands
authkit init
Initialize a new authkit.toml configuration file.
Options:
--db <TYPE>- Target database:sqliteorpostgres(default:postgres)--output <PATH>- Config file path (default:./authkit.toml)--force- Overwrite existing config file
Example:
authkit generate
Generate migration SQL files based on enabled features.
Options:
--config <PATH>- Path to authkit.toml (default:./authkit.toml)--output <DIR>- Output directory (default:./migrations)--force- Overwrite existing files
Example:
# Output:
# Generating postgres migrations to ./db/migrations
#
# Enabled features:
# ✓ Email/Password Authentication
# ✓ Email Verification
#
# Created 001_base.up.sql
# Created 001_base.down.sql
# Created 002_email_verification.up.sql
# Created 002_email_verification.down.sql
#
# ✓ Generated 4 migration files (2 features)
authkit migrate
Apply pending migrations to the database.
Options:
--db-url <URL>- Database connection URL (required, or setAUTHKIT_DATABASE_URL)--config <PATH>- Path to authkit.toml (default:./authkit.toml)--dry-run- Show what would be executed without applying
Examples:
# SQLite
# PostgreSQL
# Dry run
authkit status
Show current migration status.
Example Output:
Configuration: ./authkit.toml
Enabled features:
✓ Email/Password Authentication
✓ Email Verification
Database: postgres://localhost/authkit (PostgreSQL)
Config Database Type: postgres
Schema Version: 2
┌─────┬────────────────────┬─────────────────────┬──────────┐
│ # │ Feature │ Applied At │ Status │
├─────┼────────────────────┼─────────────────────┼──────────┤
│ 001 │ base │ 2025-01-19 10:30:00 │ Applied │
│ 002 │ email_verification │ 2025-01-19 10:30:01 │ Applied │
└─────┴────────────────────┴─────────────────────┴──────────┘
✓ Database is up to date
authkit destroy
Drop all AuthKit tables (destructive operation).
Options:
--db-url <URL>- Database connection URL (required)--force- Skip confirmation prompt
⚠️ Warning: This command permanently deletes all AuthKit tables and data!
authkit schema
Display the current schema or generate SQL.
Options:
--config <PATH>- Path to authkit.toml (optional)--db <TYPE>- Override database type:sqliteorpostgres--format <FMT>- Output format:sql,json, ortable(default:sql)--db-url <URL>- Show actual schema from database
Examples:
# Show schema based on config
# Show schema as JSON
# Show actual schema from database
Database Schema
Base Schema (email_password feature)
The base schema provides:
| Table | Description |
|---|---|
users |
Core user data (id, email, name, timestamps) |
accounts |
Links authentication providers to users |
sessions |
Active user sessions with metadata |
verification |
Tokens for password reset, magic links, etc. |
Email Verification Feature
Adds to the users table:
email_verified(BOOLEAN)email_verified_at(BIGINT/INTEGER)
Environment Variables
| Variable | Description |
|---|---|
AUTHKIT_DATABASE_URL |
Default database connection URL |
Database URL Formats
SQLite
sqlite:path/to/database.db
sqlite::memory:
PostgreSQL
postgres://username:password@host:port/database
postgresql://username:password@host/database
Compatibility
| authkit-cli | authkit (library) | Notes |
|---|---|---|
| 0.2.x | 0.2.x+ | Feature-based migrations |
| 0.1.x | 0.1.x | Legacy table-based migrations |
Development
Building
Running Tests
# Run unit tests
Safety
This project follows Rust's safety principles:
- No
unsafecode - All code uses safe Rust - Proper error handling - Uses
Resultandthiserrorfor error propagation - No panics in production paths - Uses
?operator throughout - Secure defaults - Requires confirmation for destructive operations
- Checksum verification - Ensures migrations haven't been tampered with
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Related Projects
- AuthKit - The core authentication library for Rust