#!/usr/bin/env bash # Stamps a new migration, so the name is never chosen by hand. # # panama-dev-migration "remove the stale settings-ssh-keys.sh launcher command" # # The filename is the commit timestamp of HEAD, which makes glob order # chronological without a sequence number that two branches could pick at the # same time. Two migrations authored against the same commit would collide, so # a taken name gets the next free second rather than silently overwriting. # # Developer tool, not part of any install path. See bin/panama-migrate for what # runs these and what rules they have to follow. set -euo pipefail PANAMA_PATH="${PANAMA_PATH:-$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)}" MIGRATIONS_DIR="$PANAMA_PATH/migrations" describe="${1:-}" if [[ -z "$describe" ]]; then echo 'usage: panama-dev-migration "what this repairs"' >&2 exit 2 fi stamp="$(git -C "$PANAMA_PATH" log -1 --format=%cd --date=unix 2>/dev/null || date +%s)" mkdir -p "$MIGRATIONS_DIR" while [[ -e "$MIGRATIONS_DIR/$stamp.sh" ]]; do stamp=$(( stamp + 1 )) done file="$MIGRATIONS_DIR/$stamp.sh" cat >"$file" <