From: Bill Erickson Date: Mon, 26 Oct 2015 20:31:51 +0000 (-0400) Subject: JBAS-944 SQL functions comparison tool X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=78a1a2c0a1d86bcd952683d7070bfd00581a216d;p=working%2FEvergreen.git JBAS-944 SQL functions comparison tool Tool to generate diffs for a set of SQL functions. Useful for analyzing SQL upgrade scripts. Signed-off-by: Bill Erickson --- diff --git a/KCLS/sql/schema/tools/pg-func-diffs.sh b/KCLS/sql/schema/tools/pg-func-diffs.sh new file mode 100755 index 0000000000..3f93377739 --- /dev/null +++ b/KCLS/sql/schema/tools/pg-func-diffs.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# author Bill Erickson +# Takes a list of PG function names as a command line param +# and compares stock functions to KCLS versions of those same +# functions too see which differ. Diffs for functions that +# differ are placed into the 'diffs' directory. +# Comparisons are done by extracting function definitions from +# live database instances. Change PSQL commands below to suit. +# TODO: getopts, database names via command line. more docs, etc. +FUNCS=$1 +PSQL_STOCK="psql -x -U evergreen -d evergreen" +PSQL_KCLS="psql -x -U evergreen -d eg_kcls_25" + + +mkdir -p results +mkdir -p diffs +while read func; do + echo $func; + echo "\\df+ $func;" | $PSQL_STOCK | grep -v " RECORD 1 " | \ + sed -e 's/^\s*|//g' > "results/$func-stock.txt" + echo "\\df+ $func;" | $PSQL_KCLS | grep -v " RECORD 1 " | \ + sed -e 's/^\s*|//g' | sed -e 's/\\r$//g' > "results/$func-kcls.txt" + # KCLS schema has pesky windows carriage returns +done < $FUNCS + +while read func; do + echo $func + + diff --unified=20 -Naur "results/$func-stock.txt" \ + "results/$func-kcls.txt" > "diffs/$func.txt" + + # file size 0 means no diff; kill the file. + size=$(stat -c '%s' "diffs/$func.txt"); + if [ $size == "0" ]; then + rm "diffs/$func.txt"; + fi; + +done < $FUNCS + +rm -r results; +