#database-migrations #postgresql #mysql #sql-database #sql #migration #database-schema

app dbmigrate

CLI tool to create and run database migrations. Postgres, MySQL supported.

19 releases

Uses old Rust 2015

0.4.0 Jan 22, 2023
0.3.6 Sep 4, 2021
0.3.5 Sep 29, 2017
0.3.4 Jun 30, 2017
0.1.0 Dec 19, 2015

#2155 in Database interfaces

Download history 55/week @ 2024-02-19 4/week @ 2024-02-26 198/week @ 2024-04-01

198 downloads per month


698 lines


Build Status

A tool to create and manage SQL migrations.

Databases supported

  • Postgres
  • MySQL
  • Sqlite


Using CLI

Every call to dbmigrate requires 2 arguments: database url and migrations folder. Those can be set through environment variables: DBMIGRATE_URL and DBMIGRATE_PATH, using a .env file, or as args to a call. Argument will override an environment variable.

# create a migration file
dbmigrate --url postgres://.. --path ./migrations create my_name
# apply all non applied migrations
dbmigrate --url postgres://.. --path ./migrations up
# un-apply all migrations
dbmigrate --url postgres://.. --path ./migrations down
# redo the last migration
dbmigrate --url postgres://.. --path ./migrations redo
# revert the last migration
dbmigrate --url postgres://.. --path ./migrations revert
# see list of migrations and which one is currently applied
dbmigrate --url postgres://.. --path ./migrations status

The format of the migration files is the following:


You can also pass a string to create and dbmigrate will slugify it for you:

dbmigrate --url postgres://.. --path ./migrations create "change currency table"

# gives the following files

. (dot) is not allowed in a migration name as it is the filename separator character.

Using the library

Migrations can also be done programmatically and is how the CLI tool is built.

You will need to add the dbmigrate-lib dependency to your Cargo.toml file. The best example to see how how to make it work is to look at the dbmigrate directory, which uses it to implement the CLI tool.

Test locally

Build the project first with cargo build. Assuming you use the docker images in the Makefile for pg and mysql:


./target/release/dbmigrate --url=postgres://pg@localhost:5777/migrate --path=/my/full/path/migrations status


./target/release/dbmigrate --url=mysql://mg:pass@localhost:5789/migrate --path=/my/full/path/migrations status

For Sqlite I have a Sqlite db named dbmigrate.db in the repo (gitignored):

./target/release/dbmigrate --path=/home/vincent/Code/dbmigrate/examples/migrations --url=sqlite:///dbmigrate.db status

Using a different schema

dbmigrate will use the default schema. You can override that from your database URL, for example for Postgres:

--url="postgres://postgres:@ search_path%3Dmy_app"



  • 0.1.5: update postgres dependencies
  • 0.1.4: Use postgres-native-tls
  • 0.1.1: Add features so you can only pick the database you need


  • 0.3.4: Don't crash if the terminal doesn't support colours
  • 0.3.3: Don't crash if there is no terminal
  • 0.3.2: Use features
  • 0.3.1: Refactor code to create a dbmigrate-lib and use it for the dbmigrate tool
  • 0.3.0: Add dotenv support + refactor error handling + update dependencies
  • 0.2.7: Update docs to mention sqlite support
  • 0.2.6: Support Sqlite
  • 0.2.5: Update dependencies
  • 0.2.4: Do not require DB connection to create migration file and update dependencies
  • 0.2.3: don't panic on invalid files in migration folder & ssl support for postgres
  • 0.2.2: slugify migration names and check if they are ok


This is heavily inspired by https://github.com/mattes/migrate.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~450K SLoC