#!/bin/bash

# omarchy:summary=Run pending Omarchy migrations for the current user.

set -euo pipefail

STATE_DIR="$HOME/.local/state/omarchy/migrations"
mkdir -p "$STATE_DIR"

for file in "$OMARCHY_PATH"/migrations/*.sh; do
  [[ -f $file ]] || continue
  filename=$(basename "$file")

  if [[ ! -f $STATE_DIR/$filename ]]; then
    echo -e "\e[32m\nRunning migration (${filename%.sh})\e[0m"
    bash "$file"
    touch "$STATE_DIR/$filename"
  fi
done
