parsql-cli
Command-line interface for the parsql database toolkit and migration system with interactive TUI mode.
Features
- 🎨 Interactive TUI Mode: Beautiful terminal interface with Ratatui (Claude Code style)
- 📋 Command Mode: Traditional CLI for scripts and automation
- 🔄 Migration Management: Create, run, rollback, and track database migrations
- 🗄️ Multi-Database Support: PostgreSQL and SQLite
- ⚡ Real-time Status: Live migration status and progress tracking
- 🎯 Auto-completion: Smart command suggestions in interactive mode
Installation
Or build from source:
Quick Start
1. Global Installation
# Install from crates.io (when available)
# Or install from source
2. Initialize Project
# Initialize in current directory
# This creates:
# - parsql.toml (configuration file)
# - migrations/ (directory for migration files)
# - .gitignore (ignores database files)
# - README.md (project documentation)
3. Create Your First Migration
# Edit the generated SQL files:
# - migrations/{timestamp}_create_users_table.up.sql
# - migrations/{timestamp}_create_users_table.down.sql
4. Run Migrations
# Set database URL
# or
# Run all pending migrations
# Check status
# Rollback if needed
5. Interactive TUI Mode (Optional)
# Launch interactive mode
# or just
In TUI mode:
- Use arrow keys to navigate
- Press
Enter
to select items - Press
/
for command mode - Press
?
for help Ctrl+Q
to quit
Configuration
Create a parsql.toml
file in your project root:
[]
= "postgresql://user:pass@localhost/dbname"
# Or for SQLite:
# url = "sqlite:app.db"
[]
= "migrations"
= "schema_migrations"
= true
= false
= true
Environment Variables
You can override configuration with environment variables:
DATABASE_URL
- Database connection stringPARSQL_MIGRATIONS_DIR
- Migrations directoryPARSQL_CONFIG
- Path to config file
Interactive TUI Mode
The interactive mode provides a rich terminal interface inspired by Claude Code:
Navigation
- Tab: Switch between views (Migrations, Logs, Config)
- ↑/↓ or j/k: Navigate lists
- Enter: Select/open item
- ESC or q: Go back
Command Input (/
key)
When you press /
, a command input appears at the bottom with auto-completion:
Available commands:
/help
or/h
- Show help/quit
or/q
- Exit application/connect <url>
- Connect to database/create <name>
- Create new migration/run
- Run pending migrations/rollback <version>
- Rollback to version/status
- Show migration status/validate
- Validate migrations/list
- List migrations/logs
- Show application logs/config
- Show configuration/refresh
- Refresh data
Views
Migration List View
- Shows all migrations with status (Applied/Pending)
- Color-coded for easy identification
- Quick actions:
r
to refresh,a
to apply all
Migration Detail View
- Shows SQL content of selected migration
- Actions:
r
to run,b
to rollback
Logs View
- Real-time application logs
- Color-coded by severity
Configuration View
- Current database connection
- Migration settings
Commands (CLI Mode)
parsql init
Initialize a new parsql project in the current directory.
Options:
--database-url <URL>
- Set initial database URL--migrations-dir <DIR>
- Set migrations directory (default: "migrations")
parsql migrate create
Create a new migration file.
Options:
--migration-type <TYPE>
- Migration type:sql
orrust
(default: sql)
Creates:
{timestamp}_{name}.up.sql
- Forward migration{timestamp}_{name}.down.sql
- Rollback migration
parsql migrate run
Run all pending migrations.
Options:
--database-url <URL>
- Override database URL--target <VERSION>
- Run migrations up to this version--dry-run
- Show migrations without running them
parsql migrate rollback
Rollback migrations to a specific version.
Options:
--to <VERSION>
- Target version (required)--database-url <URL>
- Override database URL--dry-run
- Show what would be rolled back
parsql migrate status
Show migration status.
Options:
--database-url <URL>
- Override database URL--detailed
- Show detailed information
Example output:
Migration Status:
10 Total migrations
7 Applied migrations
3 Pending migrations
Detailed Status:
Version Name Status Applied At Checksum
-------------- ------------------ -------- ------------------- ----------
20240101120000 create_users_table Applied 20.5.01-01 12:00:00 ✓
20240102130000 add_posts_table Applied 20.5.01-02 13:00:00 ✓
20240103140000 add_comments Pending - -
parsql migrate validate
Validate migration files.
Options:
--check-gaps
- Check for version gaps--verify-checksums
- Verify migration checksums
parsql migrate list
List available migrations.
Options:
--pending
- Show only pending migrations--applied
- Show only applied migrations
Migration File Format
SQL Migrations
Up migration ({version}_{timestamp}_{name}.up.sql
):
-- Migration: create_users_table
-- Version: 20240101120000
-- Created: 20.5.01-01 12:00:00
(
id SERIAL PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Down migration ({version}_{timestamp}_{name}.down.sql
):
-- Migration: create_users_table (rollback)
-- Version: 20240101120000
-- Created: 20.5.01-01 12:00:00
IF EXISTS users;
Rust Migrations
For complex migrations, you can use Rust:
//! Migration: complex_data_migration
//! Version: 20240101120000
//! Created: 20.5.01-01 12:00:00
use *;
;
Features
Transaction Safety
Each migration runs in its own transaction by default. If a migration fails, it's automatically rolled back.
Checksum Verification
Migrations are checksummed to detect modifications after they've been applied. The status command shows checksum mismatches.
Gap Detection
The system detects gaps in migration versions to ensure migrations run in order.
Progress Indicators
Long-running operations show progress with spinner animations and execution times.
Colored Output
- ✓ Success messages in green
- ✗ Errors in red
- ⚠ Warnings in yellow
- ℹ Info in blue
Examples
PostgreSQL Project
# Initialize
# Create migrations
# Run migrations
# Check status
# Rollback if needed
SQLite Project
# Initialize with SQLite
# Create and run migrations
# Validate migrations
Troubleshooting
Connection Errors
- Verify DATABASE_URL is correct
- For PostgreSQL: Check server is running and credentials are valid
- For SQLite: Ensure directory permissions are correct
Migration Failures
- Check SQL syntax matches your database
- Verify table/column names don't conflict
- Use
--dry-run
to preview changes - Check logs for detailed error messages
Checksum Mismatches
- Don't modify migration files after they're applied
- If you must change a migration, rollback first
- Use
validate --verify-checksums
to find issues
License
This project is part of the parsql workspace and shares its license.