Migratex
Migratex is an agnostic migration toolkit library.
Migrate anything! Anywhere! 🚀
💪 It can be used to migrate database / data / files / binaries, etc from one version to another.
- ✅ Easy to use
- ✅ Agnostic
- ✅ Standalone
- ✅ Async
- ✅ Easy to extend
- ✅ Easy to use with any storage (DB, file, etc)
- ✅ Easy to use with any migration type
- ✅ Minimal boilerplate - Ready-to-use metadata stores
Simple and intuitive API: migrate_up, migrate_down, migrate_to, migrate_to_latest, migrate_to_zero, latest_version, metadata, etc.
Quick Start
With JSON file storage
use ;
// Load or initialize metadata
let mut meta = load_or_init?;
// Run migrations
let mut mx = new;
mx.migrate_to_latest.await?;
// Save metadata
meta.save?;
With SQLite storage
use ;
use Arc;
use PathBuf;
// Connect to database
let pool = connect_to_sqlite.await?;
let storage = new;
// Load or initialize metadata
let mut meta = load_or_init.await?;
// Run migrations
let mut mx = new;
mx.migrate_to_latest.await?;
// Save metadata
meta.save.await?;
Examples
Look at the examples:
- json example - JSON file-based metadata storage
- sqlx example - SQLite database metadata storage
- custom example - Custom metadata implementation
Usage
Add this to your Cargo.toml:
[]
= "*"
Put the latest version of
migratexin yourCargo.toml!
Features
JSON
Enable the json feature for JSON file-based metadata storage:
[]
= { = "*", = ["json"] }
This provides the JsonMetadata struct for storing metadata in a JSON file.
SQLx
Enable the sqlx feature for SQLite database metadata storage:
[]
= { = "*", = ["sqlx"] }
Put the latest version of
migratexin yourCargo.toml!
This provides:
SqliteMetadata- Metadata stored in a SQLite tableSqliteStorage- Storage configurationconnect_to_sqlite()- Helper function to connect to SQLite database
Note: Other database drivers can be implemented by implementing the
Metadatatrait (look at SQLite implementation for inspiration).
Custom Metadata Storage
You can implement your own metadata storage by implementing the Metadata trait:
use ;
See the custom example for a complete implementation.
Tests
Run all tests:
Notes
- This library is in its early stages, so expect minor breaking changes.
okerris used for error handling (100% compatible withanyhow), this should work properly with any error-handling library.
LICENSE
MIT (c) 2025, Nicolas Talle.
Author
Buy me a coffee ☕ via PayPal!