3 unstable releases
Uses new Rust 2024
new 0.2.1 | May 3, 2025 |
---|---|
0.2.0 | May 3, 2025 |
0.1.0 | May 3, 2025 |
#919 in Database interfaces
20KB
299 lines
Table of Contents
- Overview
- Features
- Project Structure
- Getting Started
- Project Roadmap
- Contributing
- License
- Acknowledgments
Overview
Migro is a lightweight CLI tool for managing PostgreSQL database migrations in Rust projects. It provides a simple and intuitive way to:
- Create and manage migration files with automatically versioned naming (not using timestamps)
- Run migrations in both up and down directions
- Seed databases with test or initial data
- Organize custom SQL queries (for syntax highlighting and better readability)
- The tool follows a structured approach to database versioning, allowing teams to track schema changes and maintain consistency across development, testing, and production environments.
Migro creates and manages a directory structure with migrations, seeders, and custom queries, and automatically tracks applied migrations in a database table to ensure idempotent operations. This makes it easy to bring new environments up to date or roll back changes when needed.
With a simple command-line interface, Migro integrates easily into development workflows and CI/CD pipelines, providing essential database management capabilities for Rust applications that use PostgreSQL.
/!\ This project is in its early stages and is not yet production-ready, it does not have any last migration rollback feature yet /!\
Features
- Versioned Migrations: Automatically generates sequential version numbers for migrations, ensuring they run in the correct order
- Bidirectional Migrations: Support for both up (applying) and down (reverting) migrations
- Database Seeding: Built-in functionality to populate your database with test or initial data
- SQL Query Organization: Create and manage custom SQL queries with proper directory structure
- Idempotent Operations: Tracks applied migrations in a database table to ensure they're only run once
- Simple CLI Interface: Intuitive commands for creating, running, and reverting migrations
- Library Integration: Use as both a CLI tool or a library in your Rust projects
- PostgreSQL Support: Designed specifically for PostgreSQL databases
- Environment Variable Configuration: Uses standard DATABASE_URL environment variable for connections
- Error Handling: Robust error handling with detailed context to help troubleshoot issues
- Logging: Structured logging with tracing library for better visibility into migration operations
- Simple Project Structure: Creates a clean, organized directory structure for your database files
The tool supports the following commands:
init
: Initialize the migrations, seeders, and queries directoriescreate
: Create new migration, seeder, or query files with automatic versioningup
: Run all pending migrations (with optional seeding)down
: Revert all applied migrationsseed
: Manually run all seeders
Project Structure
└── migro/
├── Cargo.lock
├── Cargo.toml
├── LICENSE
├── README.md
└── src
├── lib.rs
└── main.rs
Getting Started
Prerequisites
Before getting started with migro, ensure your runtime environment meets the following requirements:
- Programming Language: Rust (to use the library)
- Package Manager: Cargo
Installation
Install migro using one of the following methods:
Install using crates.io:
- Install the migro CLI tool using Cargo:
cargo install migro
Build from source:
- Clone the migro repository:
git clone https://github.com/mstjr/migro
- Navigate to the project directory:
cd migro
- Install the project dependencies:
cargo build
Usage
Run migro using the following command:
Using cargo
cargo run
Contributing
- 🐛 Report Issues: Submit bugs found or log feature requests for the
migro
project. - 💡 Submit Pull Requests: Review open PRs, and submit your own PRs.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/mstjr/migro
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.'
- Push to github: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
- Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
License
This project is protected under the MIT License. For more details, refer to the LICENSE file.
Dependencies
~12–22MB
~323K SLoC