Pure Hylang database migration tool for SQLite - schema versioning and management in Lisp
Project description
Pure Hylang Migration Tool
A 100% pure Hylang v1.1.0 schema migration tool for SQLite with SQLObject integration. No Python code - everything is written in idiomatic Hylang using modern features like hyrule macros.
Features
- โจ Pure Hylang - Entire codebase in Hylang v1.1.0, no Python files
- ๐ฏ Modern Hylang idioms - Uses
hyrulemacros,letbindings, and functional patterns - ๐ฆ Pip installable - Works as a standard Python package despite being pure Hylang
- ๐ Full migration lifecycle - Create, apply, rollback, validate migrations
- ๐๏ธ SQLObject integration - Seamless ORM support
- ๐จ Colored CLI output - Beautiful terminal interface using colorama
- ๐ก๏ธ Transaction safety - All migrations run in transactions
- โ Validation & checksums - Ensure migration integrity
- ๐ Dry-run mode - Preview changes before applying
Installation
Using UV (Recommended)
UV is a fast Python package manager that provides excellent environment handling:
# Clone the repository
git clone https://github.com/yourusername/hylang-migrations.git
cd hylang-migrations
# Create virtual environment and install
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
# The tool is now available
hylang-migrate --help
Using pip
# Clone the repository
git clone https://github.com/yourusername/hylang-migrations.git
cd hylang-migrations
# Install in development mode
pip install -e .
# Or build and install
pip install build
python -m build
pip install dist/hylang_migrations-*.whl
From PyPI (when published)
pip install hylang-migrations
Quick Start
1. Initialize Your Project
cd your-project
hylang-migrate init
This creates:
migrations/directory for migration files.migrationsconfiguration file (in Hylang format)- Initial project structure
2. Create a Migration
hylang-migrate create create_users_table
This generates a timestamped Hylang migration file:
;;; Migration: create_users_table
;;; Version: 20240101120000
(defclass CreateUsersTable []
(defn up [self connection]
"Apply migration"
(connection.execute
"CREATE TABLE users (
id INTEGER PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)"))
(defn down [self connection]
"Rollback migration"
(connection.execute "DROP TABLE IF EXISTS users")))
(setv migration (CreateUsersTable))
3. Run Migrations
# Apply all pending migrations
hylang-migrate migrate
# Preview changes (dry run)
hylang-migrate migrate --dry-run
# Migrate to specific version
hylang-migrate migrate --target 20240101120000
4. Check Status
hylang-migrate status
Output:
๐ Migration Status
Database: database.db
Migrations: migrations/
โ
Applied Migrations:
Version Name Applied At
20240101120000 create_users_table 2024-01-01 12:00:00
โณ Pending Migrations:
Version Name
20240101130000 add_user_profiles
5. Rollback
# Rollback last migration
hylang-migrate rollback
# Rollback multiple migrations
hylang-migrate rollback --steps 3
# Rollback to specific version
hylang-migrate rollback --to 20240101120000
Command Reference
Global Options
--config PATH- Configuration file path (default:.migrations)--db PATH- Database file path (default:database.db)--migrations-dir PATH- Migrations directory (default:migrations)--verbose- Verbose output
Commands
| Command | Description | Options |
|---|---|---|
init |
Initialize migration system | - |
create NAME |
Create new migration | - |
migrate |
Run pending migrations | --target VERSION, --dry-run |
rollback |
Rollback migrations | --steps N, --to VERSION, --dry-run |
status |
Show migration status | - |
list |
List all migrations | --pending, --applied |
show VERSION |
Show migration details | - |
validate |
Validate migration files | - |
Configuration
Hylang Format (.migrations)
{
:database {
:path "database.db"
:type "sqlite"
}
:migrations {
:directory "migrations"
:table-name "migration_history"
:auto-transaction true
:verify-checksums true
}
:sqlobject {
:debug false
:cache true
:lazy-update true
}
:logging {
:level "INFO"
:file "migrations.log"
}
}
Environment Variables
export DB_PATH=production.db
export MIGRATIONS_DIR=db/migrations
export SQLOBJECT_DEBUG=true
Writing Migrations
Basic Migration Structure
(require hyrule [-> ->> as->])
(import sqlite3)
(defclass MigrationName []
(defn __init__ [self]
(setv self.version "20240101120000")
(setv self.name "migration_name"))
(defn up [self connection]
"Apply migration"
;; Your forward migration logic
)
(defn down [self connection]
"Rollback migration"
;; Your rollback logic
)
(defn validate [self connection]
"Optional validation"
True)
(defn get-checksum [self]
"Calculate checksum"
(import hashlib)
(-> (hashlib.sha256)
(.update (.encode (+ self.version self.name) "utf-8"))
(.hexdigest))))
(setv migration (MigrationName))
Using SQLObject Models
(import sqlobject [SQLObject StringCol IntCol DateTimeCol BoolCol])
(import datetime [datetime])
(defclass User [SQLObject]
(setv _table "users")
(setv username (StringCol :unique True :notNone True))
(setv email (StringCol :unique True :notNone True))
(setv is-active (BoolCol :default True))
(setv created-at (DateTimeCol :default datetime.now)))
Pure Hylang Implementation
This tool is written entirely in Hylang v1.1.0 with modern idioms:
Key Files (all .hy):
cli.hy- Command-line interface with argparse and coloramamigrations.hy- Core migration engineconfig.hy- Configuration managementutils.hy- Utility functionstemplates.hy- Migration and model generators
Hylang v1.1.0 Features Used:
require hyrulefor modern macrosletbindings for local scopelforlist comprehensions#**for keyword arguments- f-strings for formatting
- Pattern matching with
cond
Development
Setup Development Environment
# Clone repo
git clone https://github.com/yourusername/hylang-migrations.git
cd hylang-migrations
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e ".[dev]"
Running Tests
# Run all tests
pytest tests/
# Run specific test
pytest tests/test_migrations.hy
# With coverage
pytest --cov=hylang_migrations tests/
Building Package
# Build distribution
python -m build
# Upload to TestPyPI
python -m twine upload --repository testpypi dist/*
# Upload to PyPI
python -m twine upload dist/*
Project Structure
hylang-migrations/
โโโ src/
โ โโโ hylang_migrations/
โ โโโ __init__.hy # Package initialization
โ โโโ __main__.hy # Module entry point
โ โโโ cli.hy # CLI implementation
โ โโโ migrations.hy # Core engine
โ โโโ config.hy # Configuration
โ โโโ utils.hy # Utilities
โ โโโ templates.hy # Generators
โโโ migrations/ # User migrations directory
โ โโโ *.hy # Migration files
โโโ tests/ # Test suite
โ โโโ test_*.hy # Test files
โโโ pyproject.toml # Package configuration
โโโ setup.hy # Hylang setup script
โโโ README.md # This file
โโโ LICENSE # MIT License
Why Pure Hylang?
This project demonstrates that complex tools can be written entirely in Hylang without any Python code:
- Language Purity - Shows Hylang's completeness as a language
- Lisp Power - Leverages macros and functional programming
- Python Ecosystem - Still integrates seamlessly with pip/PyPI
- Modern Hylang - Uses latest v1.1.0 features and idioms
- Real-World Tool - Not just a toy, but a production-ready tool
Claude Code Integration
This package includes Claude Code subagents to help you work with Hylang migrations more effectively!
Installing Claude Agents
# Install the Hylang migrations assistant
hylang-migrate install-claude-agent
# The agents are now available in Claude Code!
Available Agents
-
hylang-migrate-assistant - Expert help with:
- Creating and managing migrations
- Debugging migration issues
- Schema design best practices
- Hylang v1.1.0 migration syntax
-
hyrule-expert - Hylang/Hyrule language expert for:
- Conditionals (
if,when,cond) - Loops and comprehensions
- String formatting (
.formatvs f-strings) - Hyrule macros and utilities
- Conditionals (
To use these agents in Claude Code, type /agents and select the appropriate assistant.
Contributing
Contributions must be in pure Hylang! We welcome:
- Bug fixes
- New features
- Documentation improvements
- Test coverage
- Performance optimizations
Please ensure all code follows Hylang v1.1.0 idioms and includes tests.
License
MIT License - See LICENSE file for details.
Acknowledgments
- Hylang community for the amazing Lisp-on-Python language
- SQLObject for the ORM functionality
- All contributors to the Python ecosystem
Remember: This entire tool is written in pure Hylang - no Python files! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hylang_migrations-0.1.0.tar.gz.
File metadata
- Download URL: hylang_migrations-0.1.0.tar.gz
- Upload date:
- Size: 38.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa7f402a40d32339f9c08ecace6e9604cb9dfc2db6c2ad42204c08ca814d1e9a
|
|
| MD5 |
b351af794bbbf033b3f3fc222e90d628
|
|
| BLAKE2b-256 |
5b946e4ce7f268cafc44990def486801a1d07ce8e5f3c57fac705d0625c41669
|
File details
Details for the file hylang_migrations-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hylang_migrations-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e546520a3f3adadea0c4600049b1c9d2629233066616f667f86d843c273e045c
|
|
| MD5 |
c47d7954045d7d190f87c7a8f362a23a
|
|
| BLAKE2b-256 |
640053717d614f8ed14c8e51728d49e3ba27b0cda1535a0c31a93aeb6b62417e
|