mirror of
https://github.com/basecamp/omarchy.git
synced 2025-08-01 22:39:24 +00:00
Track migrations via state files to avoid running migrations that have already been performed. (#411)
This commit is contained in:
@ -1,26 +1,32 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
STATE_DIR="$HOME/.local/state/omarchy/migrations"
|
||||||
|
|
||||||
cd ~/.local/share/omarchy
|
cd ~/.local/share/omarchy
|
||||||
|
|
||||||
if [[ $1 == "all" ]]; then
|
# Create the migrations state directory, we will store an empty file for each migration that has already been performed.
|
||||||
# Run all migrations since the root commit
|
mkdir -p "$STATE_DIR"
|
||||||
migration_starting_point=$(git log --max-parents=0 --first-parent --format="%H")
|
|
||||||
else
|
|
||||||
# Remember the commit we're at before upgrading in order to only run new migrations
|
|
||||||
migration_starting_point=$(git log -1 --format=%H)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get the latest while trying to preserve any modifications
|
# Get the latest while trying to preserve any modifications
|
||||||
git pull --autostash
|
git pull --autostash
|
||||||
git diff --check || git reset --merge
|
git diff --check || git reset --merge
|
||||||
|
|
||||||
# Run any pending migrations
|
# Run any pending migrations
|
||||||
for file in $(git diff --name-only --diff-filter=A $migration_starting_point.. migrations/*.sh); do
|
for file in migrations/*.sh; do
|
||||||
filename=$(basename "$file")
|
filename=$(basename "$file")
|
||||||
migrate_at="${filename%.sh}"
|
migrate_at="${filename%.sh}"
|
||||||
|
|
||||||
echo -e "\e[32m\nRunning migration ($migrate_at)\e[0m"
|
# Migration already applied, to re-run it simply delete the state file and try again
|
||||||
source $file
|
[ -e "${STATE_DIR}/$filename" ] && continue
|
||||||
|
|
||||||
|
echo -e "\e[32m\nRunning migration (${filename%.sh})\e[0m"
|
||||||
|
if source $file; then
|
||||||
|
touch "${STATE_DIR}/$filename"
|
||||||
|
echo -e "\t\e[32m✔ Succeess\e[0m"
|
||||||
|
else
|
||||||
|
echo -e "\t\e[31m✖ FAILED\e[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Update system packages
|
# Update system packages
|
||||||
|
Reference in New Issue
Block a user