Bash-Migration is a tool for applying / reversing migrations to a server.
- Apply migrations to your server
- Reverse migrations you don't need anymore
- Automatic rollback when an action failed
- Possibility to apply or reverse specific migrations
- Uses a semaphore to prevent running in parallel
Name | Version | Description |
---|---|---|
bash | 5.0.3 | For running the BashMigration script |
grep | 3.3 | For extracting informations from the filename |
SQLite | 3.28.0 | As persistent data store |
- Instead of bash you could also use zsh (tested with version 5.5.1)
- The
sqlite3
command must be available in the command line.
Name | Description |
---|---|
migrate | Migrates all revisions which are located in the migrations directory |
unmigrate | Reversing applied migrations |
list | List the status of all migrations |
version | Shows the current version |
The migrate
and unmigrate
both support arguments.
They support:
all
: Migrating / unmigrating all revisions<revision id>
: Migrating / unmigrating a specific revision<revision id> <revision id>
: Migrating / unmigrating multiple specific revisions
By default the all
argument is used.
- Create a directory called
migrations
- Create your first migration with the following pattern
id_name_of_my_migration.sh
- ID is an integer
- The name is up to you for identifying what the migration does
- Declare the functions
migrateUp
andmigrateDown
(see below for an example) - Fill both functions with the commands you would like to run
- Run the
migrate
command - Be happy!
Here is an example for a migration file
function migrateUp() {
echo "Migrating up"
return 0
}
function migrateDown() {
echo "Migrating down"
return 0
}
When one of the functions returns the value 1
, the action will be considered as unsuccessful and we rollback.
- Initialize a git repository in an empty directory
- Add BashMigration as submodule:
git submodule add -b master https://github.com/YannickFricke/BashMigration.git BashMigration
- Create the
migrations
directory - Create your first migration file (as described)
- Start the script with
./BashMigration/BashMigration.sh migrate
You could also create a Makefile
for easier usage.
Take a look into the wiki for additional informations.