dbmigrate

Build Status

A tool to create and manage SQL migrations.

Databases supported

Usage

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.

```bash

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: bash 0001.initial_db.up.sql 0001.initial_db.down.sql

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

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

gives the following files

0001.changecurrencytable.up.sql 0001.changecurrencytable.down.sql ```

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

Test locally

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

Postgres:

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

MySQL: bash ./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): bash ./target/release/dbmigrate --path=/home/vincent/Code/dbmigrate/examples/migrations --url=sqlite:///dbmigrate.db status

TODO

Changelog

Acknowledgments

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

License

Licensed under either of

at your option.

Contribution

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.