Mroll migration tool
mroll has been designed to aid MonetDB users with managing database migrations.
The functionality covers both roll forward and backward migration functionality.
Although you can deploy mroll from any point in time onwards, it is advised to use it
from day one, i.e. the creation of the database.
mroll has been used internally to manage the continuous integration workflow of MonetDB.
Install
Install mroll from PyPi
$ pip install mroll
Synopsis
The command synopsis summarizes the functionality.
$ mroll --help
Usage: commands.py [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...
Options:
--help Show this message and exit.
Commands:
config Set up mroll configuration under $HOME/.config/mroll
history Shows applied revisions.
init Creates mroll_revisions tbl.
revision Creates new revision from a template.
rollback Downgrades to previous revision by default.
setup Set up work directory.
show Shows revisions information.
upgrade Applies all revisions not yet applied in work dir.
version Shows current version
Each command may come with some options, explained by the --help addition.
For example, the location of the migration directory can be specified when you install mroll
with an option --path option to specify location. For an example, --path "/tmp/migration" location.
To update/set mroll configuration use the config command.
For example to update configuration setting for working directory path run.
mroll config -p <workdir_path>
Usage
To illustrate the functionality we walk you through the steps to get a MonetDB database, called
demo, created and managed. We assume you have downloaded mroll (see below) and are all set to give it a try.
Setup
mroll needs a working directory for each database you want to manage. There is no restriction on
its location, but you could keep the migration scripts in your application
folder, e.g. .../app/migrations. From the .../app directory issue the command:
$ mroll setup
ok
A subdirectory migrations is being created to manage migrations versions.
Configuration
mroll needs information on the database whereabouts and credentials to initiate the migration steps.
Make sure you have already created and released the demo database using the monetdb tools.
Then complete the file migrations/mroll.ini to something like:
[db]
db_name=demo
user=monetdb
password=monetdb
port=50000
[mroll]
rev_history_tbl_name = mroll_revisions
The final step for managing the migrations is
$ mroll init
Define the first revision
The empty database will be populated with a database schema. For this we define a revision. Revision names are generated
$ mroll revision -m "Initialize the database"
ok
$ mroll show all_revisions
<Revision id=fe00de6bfa19 description=Initialize the database>
A new revison file was added under /tmp/migrations/versions.
Open it and add the SQL commands under -- migration:upgrade and -- migration:downgrade sections.
vi tmp/migrations/versions/<rev_file>
-- identifiers used by mroll
-- id=fe00de6bfa19
-- description=create tbl foo
-- ts=2020-05-08T14:19:46.839773
-- migration:upgrade
create table foo (a string, b string);
alter table foo add constraint foo_pk primary key (a);
-- migration:downgrade
drop table foo;
Then run "upgrade" command.
$ mroll upgrade
Done
Inspect what has being applied with "history" command
$ mroll history
<Revision id=fe00de6bfa19 description=create tbl foo>
For revisions overview use mroll show [all|pending|applied], mroll applied is equivalent to
mroll history.
$mroll show applied
<Revision id=fe00de6bfa19 description=create tbl foo>
To revert last applied revision run the rollback command. That will run the sql under migration:downgrade
section.
$ mroll rollback
Rolling back id=fe00de6bfa19 description=create tbl foo ...
Done
Development
Developer notes
mroll is developed using Poetry, for dependency management and
packaging.
Installation for development
In order to install mroll do the following:
pip3 install --user poetry
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
export PATH="$PATH:$PYTHON_BIN_PATH"
git clone git@github.com:MonetDBSolutions/mroll.git
cd mroll
poetry install
poetry run mroll/commands.py --help
Install project dependencies with
poetry install
This will create virtual environment and install dependencies from the poetry.lock file. Any of the above
commands then can be run with poetry
poetry run mroll/commands.py <command>
Testing
Run all unit tests
make test
Metadata
Release files for mroll 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mroll-0.4.0.tar.gz | 17.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mroll-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.5 kB
Release files / mroll-0.4.0.tar.gz
| Download URL | mroll-0.4.0.tar.gz |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68c52eb4b8ab47a827a943b8f67778a431ca029150663bbe7bfce59e67d0ec9f
|
|
BLAKE2b-256 checksum How to use checksums |
defb77e6666897deb20ac4ceaf398e5962895574ed1768aa597cbf2da2c8c2b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.8 Linux/6.0.9-200.fc36.x86_64
|
Release files / mroll-0.4.0-py3-none-any.whl
| Download URL | mroll-0.4.0-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
908b4f221daaab050b366fe151fc4e684e8972472203418d5d0490d396469b1e
|
|
BLAKE2b-256 checksum How to use checksums |
f8e4563595d2f54487bb81f6dd417b48542cf3e1ee714069bcdd733c97539a60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.8 Linux/6.0.9-200.fc36.x86_64
|
Security for mroll 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.