Created
August 29, 2020 18:02
-
-
Save rcy/cc05a00138b872a2d98ee79139cd68c5 to your computer and use it in GitHub Desktop.
Recompute hashes for graphile-migrate migration files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# usage: rehash.sh committed/*.sql | |
# | |
# This will update each file's Previous and Hash values | |
# | |
function sum { | |
sha1sum | cut -d' ' -f1 | |
} | |
function rehash { | |
local file=$1 | |
local prev=$2 | |
if test -z $prev; then | |
prevhash='-' | |
hash=sha1:$(tail +4 $file | sum) | |
else | |
prevhash=$(head -2 $prev | tail -1 | cut -f3 -d' ') | |
local tmp=$(mktemp) | |
echo $prevhash > $tmp | |
tail +4 $file >> $tmp | |
hash=sha1:$(cat $tmp | sum) | |
rm $tmp | |
fi | |
echo "--! Previous: $prevhash" | |
echo "--! Hash: $hash" | |
tail +3 $file | |
} | |
tmp=$(mktemp) | |
for file in $@; do | |
rehash $file $prev > $tmp | |
if ! diff -q $file $tmp; then | |
mv $tmp $file | |
fi | |
prev=$file | |
done | |
rm -f $tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this after needing to repair a migration that named a role literally rather than using :DATABASE_VISITOR