Cetane
Django-inspired database migrations for Rust with automatic reversibility.
Features
- Backend-agnostic: SQLite, PostgreSQL, and MySQL support
- Type-safe SQL generation: Uses sea-query for compile-time safety
- Automatic reversibility: Most operations generate their own reverse migrations
- Dependency ordering: Migrations declare dependencies, cetane resolves the order
- Transaction support: Atomic migrations where backends support it (PostgreSQL, SQLite)
Usage
use *;
let mut registry = new;
registry.register;
registry.register;
// Run migrations
let state = new;
let mut migrator = new;
migrator.migrate_forward?;
Operations
| Operation | Description | Auto-reversible |
|---|---|---|
CreateTable |
Create a new table | Yes |
DropTable |
Drop a table | With field definitions |
RenameTable |
Rename a table | Yes |
AddField |
Add a column | Yes |
RemoveField |
Remove a column | With field definition |
RenameField |
Rename a column | Yes |
AlterField |
Modify column type/constraints | With reverse changes |
AddIndex |
Create an index | Yes |
RemoveIndex |
Drop an index | With index definition |
AddConstraint |
Add a constraint | Yes |
RemoveConstraint |
Remove a constraint | With constraint definition |
RunSql |
Execute raw SQL | With reverse SQL |
Feature Flags
sqlite- SQLite support (includesrusqlite)postgres- PostgreSQL support (includespostgres)mysql- MySQL support (includesmysql)
License
BSD 2-Clause License. See LICENSE for details.