- Notifications
You must be signed in to change notification settings - Fork9
A migration manager written in Rust that attempts to be smart yet minimal
License
byronwasti/movine
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
NOTE: This project is no longer actively maintained. It was originally a Proof-of-concept and I never got around to properly fixing it up, and don't plan to. Feel free to use at your own risk, and I'll still take a look every now and then to merge fixes.
Movine is a simple database migration manager that aims to be compatible with real-world migration work. Many migration managers get confused with complicated development strategies for migrations. Oftentimes migration managers do not warn you if the SQL saved in git differs from what was actually run on the database. Movine solves this issue by keeping track of the unique hashes for theup.sql anddown.sql for each migration, and provides tools for fixing issues. This allows users to easily keep track of whether their local migration history matches the one on the database.
This project is currently in early stages.
Movine doesnot aim to be an ORM. Considerdiesel instead if you want an ORM.
Movine keeps track of four different states of migrations on the database. There are the basic ones:
- Applied: Found locally and applied to the database
- Pending: Found locally and not applied to the database
Then there are the more complicated ones, which Movine was specifically designed to handle:
- Variant: Found locally but a different version is applied to the database
- Divergent: Not found locally but applied to the database
A 3.5 minute video showcasing the various tools Movine provides.
The first step to get started with Movine is to set the configuration. Configuration can be supplied either through amovile.toml file or environment variables:
If Movine finds a config file namedmovine.toml it will use the parameters specified.
[postgres]host = {host}database = {db}user = {username}password = {pass}port = {port}sslrootcert = {cert filename}## Or use the Sqlite adaptor[sqlite]file={file}## Or supply a database URLdatabase_url={url_string}
Note: SSLRootCert currently does not work when supplying a database_url.Note: You should only specify connection details for one database type, or Movine will implicitly choose one
You can configure the PostgreSQL adaptor using the environment variables described in thePostgreSQL documentation. SpecificallyPGHOST,PGPORT,PGDATABASE,PGUSER, andPGPASSWORD andPGSSLROOTCERT are supported.
You can configure the SQLite adaptor using anSQLITE_FILE environment variable.
Finally, you can also supply aDATABASE_URL environment variable.
Note: SSLRootCert does not work when using a database URL.
Movine supports.env files as a source of configuration.
Next, you can run theinit command to set everything up, thegenerate command to create your first migration, and once those are written you can runup to apply them.
$ movine init$ tree migrations/migrations/└── 1970-01-01-000000_movine_init ├── down.sql └── up.sql1 directory, 2 files$ movine generate create_new_table$ tree migrations/migrations/├── 1970-01-01-000000_movine_init│ ├── down.sql│ └── up.sql└── 2019-03-17-163451_create_new_table ├── down.sql └── up.sql2 directories, 4 files$ movine up$ movine status2019-03-17 16:34:51 UTC - Applied 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_initThere are a few commands that Movine uses, and all of them can be listed by using--help on the command line.
Theinit command will run the initialization routine for Movine, which will create a table on the database to keep track of migrations and create a local migrations folder.
$ movine init$ lsmigrations/ movine.toml$ tree migrations/migrations/└── 1970-01-01-000000_movine_init ├── down.sql └── up.sql1 directory, 2 files$ psql $PARAMS -c "\d" List of relations Schema | Name | Type | Owner--------+--------------------------+----------+-------- public | movine_migrations | table | movine public | movine_migrations_id_seq | sequence | movineThegenerate command will generate a folder with the current date and the given name in themigrations/ directory with blankup.sql anddown.sql files.
$ movine generate create_new_table$ tree migrations/migrations/├── 1970-01-01-000000_movine_init│ ├── down.sql│ └── up.sql└── 2019-03-17-163451_create_new_table ├── down.sql └── up.sql2 directories, 4 filesThestatus command will tell you the current state of all migrations, both local and on the database.
$ movine status2019-03-17 16:34:51 UTC - Pending 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_initTheup command will run all pending migrations. You can also run with the-p flag to show the migration plan without running it. This is true for all commands that modify the database and is useful for seeing if Movine will do what you expect.
$ movine up -p1. Up - 2019-03-17-163451_create_new_table$ movine status2019-03-17 16:34:51 UTC - Pending 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_init$ movine up$ movine status2019-03-17 16:34:51 UTC - Applied 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_initThedown command will rollback the most recent migration.
$ movine down$ movine status2019-03-17 16:34:51 UTC - Pending 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_initTheredo command will rollback and then re-apply the most recent applied migration or variant migration.Note: If the latest migration isdivergent then redo will simply skip it. Be careful, and runfix if you want to fixdivergent migrations.
$ movine status2019-03-17 16:34:51 UTC - Variant 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_init$ movine redo$ movine status2019-03-17 16:34:51 UTC - Applied 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_initThefix command will rollback everything until there are no divergent or variant migrations, and then apply all migrationsexcept the migrations that were pending at the start.
$ movine status2019-03-17 16:41:07 UTC - Pending 2019-03-17-164107_create_another_table2019-03-17 16:40:59 UTC - Divergent 2019-03-17-164059_modify_table2019-03-17 16:34:51 UTC - Variant 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_init$ movine fix$ movine status2019-03-17 16:41:07 UTC - Pending 2019-03-17-164107_create_another_table2019-03-17 16:34:51 UTC - Applied 2019-03-17-163451_create_new_table1970-01-01 00:00:00 UTC - Applied 1970-01-01-000000_movine_initThecustom command will allow you to specify your own migration strategy (in case Movine is not smart enough).Note: this is currently not implemented
Note: While theMovine implementation is stable at this point, theconfig API may be in flux (specifically the helper functions). Please let me know any feedback!
Movine can be used as a library like so (using helper functions to load the database connection):
use movine::{Movine,Config};use movine::errors::Error;fnmain() ->Result<(),Error>{let config =Config::load(&"movine.toml")?;letmut conn = config.into_sqlite_conn();letmut movine =Movine::new(&mut conn); movine.up()?;Ok(())}
Or if you already have a connection:
use movine::{Movine,Config};use movine::errors::Error;fnmain() ->Result<(),Error>{// Same concept with a postgres connection!letmut conn = rusqlite::Connection::open("file.db")?;letmut movine =Movine::new(&mut conn); movine.up()?;Ok(())}
- You accept the risks of pre-1.0 software
- You want to write raw sql for your migrations
- You have a shared database that has migrations developed by multiple developers
- You want a migration management solution that works for the developers
- You want long battle-tested database migration manager
- You want ORM integration (considerdiesel instead)
- You don't see value in keeping track of variant or divergent migrations
About
A migration manager written in Rust that attempts to be smart yet minimal
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.