#migration #postgresql #tool #migro

bin+lib migro

A simple migration tool for PostgreSQL

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

MIT/Apache

20KB
299 lines

license last-commit repo-top-language repo-language-count


Table of Contents


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 directories
  • create: Create new migration, seeder, or query files with automatic versioning
  • up: Run all pending migrations (with optional seeding)
  • down: Revert all applied migrations
  • seed: 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:

  1. Install the migro CLI tool using Cargo:
cargo install migro

Build from source:

  1. Clone the migro repository:
git clone https://github.com/mstjr/migro
  1. Navigate to the project directory:
cd migro
  1. Install the project dependencies:

Using cargo  

cargo build

Usage

Run migro using the following command: Using cargo  

cargo run

Contributing

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/mstjr/migro
    
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
    
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
    
  6. Push to github: Push the changes to your forked repository.
    git push origin new-feature-x
    
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph


License

This project is protected under the MIT License. For more details, refer to the LICENSE file.


Dependencies

~12–22MB
~323K SLoC