dbmigrate
A tool to create and manage SQL migrations.
Databases supported
- Postgres
- MySQL
- Sqlite
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
or as args to a call. Argument will override an environment variable.
# create a migration file
# apply all non applied migrations
# un-apply all migrations
# redo the last migration
# revert the last migration
# see list of migrations and which one is currently applied
The format of the migration files is the following:
You can also pass a string to create
and dbmigrate will slugify it for you:
# gives the following files
.
(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:
MySQL:
For Sqlite I have a Sqlite db named dbmigrate.db
in the repo (gitignored):
TODO
- find a way to do integration testing on travis + rust (use a python script?)
- move to gitlab?
Changelog
- 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
Acknowledgments
This is heavily inspired by https://github.com/mattes/migrate.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.