Skip to content

Instantly share code, notes, and snippets.

@svandragt
Last active May 26, 2023 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svandragt/73caba554f9e6a934cda926a2c2ece91 to your computer and use it in GitHub Desktop.
Save svandragt/73caba554f9e6a934cda926a2c2ece91 to your computer and use it in GitHub Desktop.
Basic migrate script that when run calls a number of bash functions to run only if they're not already migrated.
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
do_upgrade() {
VERSION_FILE="migrations.version"
if [ ! -f $VERSION_FILE ]; then
touch $VERSION_FILE
fi
# List all the upgrades here
do_upgrade_profiler
}
do_upgrade_profiler() {
CHECK="profiler"
if ! grep -Fxq $CHECK "$VERSION_FILE"; then
echo "📦 Installing Profiler"
echo "<Installation routines>" &&
echo $CHECK >>$VERSION_FILE
fi
}
do_upgrade
# this file contains a line per migration id
@svandragt
Copy link
Author

After running the version file contains the line "profiler" and the second time this script is run nothing happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment