Skip to content

Commit

Permalink
Updating migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
IPadawans committed Apr 24, 2024
1 parent 4ee5d4a commit f780927
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions scripts/migrations/migrations.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
function version_greater_or_equal() {
[[ "$1" = "$(echo -e "$1\n$2" | sort -V | tail -n 1)" ]]
function version_greater_than() {
[[ "$1" = "$(echo -e "$1\n$2" | sort -V | tail -n 1)" ]] && [[ "$1" != "$2" ]]
}

function run_migrations() {
echo_title "Starting migrations..."
echo_white

VERSION=$1
VERSION_WITHOUT_V="${VERSION#v}"
cd $INFRA_PATH

euclid_field_version=$(jq -r '.version // empty' "$ROOT_PATH/euclid.json") # Versions previous 0.9.0 doesn't have version field
if version_greater_or_equal $VERSION_WITHOUT_V "0.9.0" || [ -z "$euclid_field_version" ]; then
CURRENT_VERSION=$(jq -r '.version // "0.0.0"' "$ROOT_PATH/euclid.json")
CURRENT_VERSION_WITHOUT_V="${CURRENT_VERSION#v}"

if version_greater_than "0.9.0" $CURRENT_VERSION_WITHOUT_V; then
echo "Running migration v0.9.0"
cd $SCRIPTS_PATH
source ./migrations/v0.9.0.sh
migrate_v_0_9_0
VERSION="0.9.0"
current_version="0.9.0"
jq --arg current_version "$current_version" '.version = $current_version' $ROOT_PATH/euclid.json > $ROOT_PATH/temp.json && mv $ROOT_PATH/temp.json $ROOT_PATH/euclid.json
fi

if version_greater_or_equal $VERSION_WITHOUT_V "0.10.0"; then
if version_greater_than "0.10.0" $CURRENT_VERSION_WITHOUT_V; then
echo "Running migration v0.10.0"
cd $SCRIPTS_PATH
source ./migrations/v0.10.0.sh
migrate_v_0_10_0
VERSION="0.10.0"
current_version="0.10.0"
jq --arg current_version "$current_version" '.version = $current_version' $ROOT_PATH/euclid.json > $ROOT_PATH/temp.json && mv $ROOT_PATH/temp.json $ROOT_PATH/euclid.json
fi

# Clean up
rm -r -f $INFRA_PATH/euclid-development-environment 2>/dev/null
rm -f $ROOT_PATH/old-euclid.json 2>/dev/null
contents="$(jq --arg VERSION "$VERSION" ".version = \"$VERSION\"" $ROOT_PATH/euclid.json)" &&
echo -E "${contents}" >$ROOT_PATH/euclid.json


echo "migrations finished..."
echo
}
}

0 comments on commit f780927

Please sign in to comment.