A migration runner, not especially targeting sql databases.
docker run -v $PWD:/usr/src/app -u 1000:1000 docteurklein/migrate
migrate add 'create_missing_indexes' sh
migrate pg://prod up-to 'some_next_step'
migrate pg://prod up-to --latest
migrate pg://prod rollback-to 'some_previous_step'
migrate pg://prod rollback-to --zero
migrate pg: previous
Note: executing this twice would end up to where you started.
All commands having side effects have the --dry-run and --verbose option. If you use them both, you'll see exactly what would be executed.
You can specify many scripts per step that matches the glob pattern:
migrations/*/*up*
migrations/*/*rollback*
migrations/*/*verify*
Use numeric prefixes to guarantee the order of execution, for example:
migrations/create_missing_indexes/1-up.shmigrations/create_missing_indexes/2-up.shA local plan file is compared to the target's state and decides which steps are yet to be executed.
Steps are executed sequentially.
After each step execution, the verify script is invoked.
If verify exits with a status code different than 0, all rollback scripts from impacted steps are executed, and the whole migration stops.
The target is represented by an URL (containing credentials and configuration). The target is the thing we want to mutate. The target stores the history of all executed steps.
Currently supported targets are:
example: migrate pg://user:password@hostname/db_name status
Those variables take precedence over the values passed in URL.
POSTGRES_DBNAMEPOSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_PASSWORD_FILE (wins over POSTGRES_PASSWORD)POSTGRES_HOSTPOSTGRES_PORTexample: migrate sqlite:path/to/some_file.sqlite status
You can write your own python module that respects the Context interface,
and use it like this:
migrate some.python.module:some-host/some/param status`
Files ending with .sql are treated differently than others if the target supports it:
their contents are passed to the current transaction opened on the target.
migrations/create_missing_indexes/up#!/usr/bin/env sh
curl -X POST http://elasticsearch.local:9200/_reindex -d@- <<JSON
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}
JSON
migrations/create_missing_indexes/rollback#!/usr/bin/env sh
curl -X POST http://elasticsearch.local:9200/_reindex -d@- <<JSON
{
"source": {
"index": "new_twitter"
},
"dest": {
"index": "twitter"
}
}
JSON
migrations/create_missing_indexes/verify#!/usr/bin/env sh
curl -f -X GET http://elasticsearch.local:9200/twitter
Each step uses executable files with shebang (except .sql files) for a maximum flexibility.
./bin/tests
Content type
Image
Digest
Size
20.5 MB
Last updated
over 6 years ago
docker pull docteurklein/migrate