66 lines
2.6 KiB
Bash
66 lines
2.6 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
# check-schema-diff.sh <path-to-manager.zip>
|
||
|
|
#
|
||
|
|
# Runs ICPManager's diff-meta against the live DB, using a staged copy of
|
||
|
|
# manager.zip that is NOT yet installed anywhere live. Per ICPManager.java
|
||
|
|
# (getAppMeta/getDbMeta): dump-appmeta just scans a directory of compiled
|
||
|
|
# classes already on the classpath (the "model" dir bundled inside
|
||
|
|
# manager.zip), and dump-dbmeta just opens a JDBC connection - neither one
|
||
|
|
# touches the running webapp or Tomcat at all. That means this check can
|
||
|
|
# run BEFORE anything live is touched, so a deploy mode that assumes "no
|
||
|
|
# DB changes" (hotfix-code) can verify that assumption first - a wrong
|
||
|
|
# assumption costs zero downtime instead of a broken mid-upgrade state.
|
||
|
|
#
|
||
|
|
# diff-meta itself has no dedicated exit code for "differences found" vs
|
||
|
|
# "none" (see ICPManager.doDiffMeta - there's no System.exit tied to the
|
||
|
|
# diff result at all) - the only signal is the literal stdout line
|
||
|
|
# "No differences detected". This script imposes the contract callers
|
||
|
|
# actually need:
|
||
|
|
# exit 0 - clean, no schema differences
|
||
|
|
# exit 1 - the check itself failed to run (bad manager.conf, DB
|
||
|
|
# unreachable, manager.zip missing/incomplete, etc.) - treat
|
||
|
|
# this as at least as serious as differences found, not as
|
||
|
|
# "probably fine"
|
||
|
|
# exit 2 - differences were detected (see stdout for the diff)
|
||
|
|
#
|
||
|
|
# Deliberately reuses manager-exec.sh's own classpath/invocation instead
|
||
|
|
# of duplicating the "java -cp model:libs/...jar icp.ICPManager manager.conf
|
||
|
|
# -exec ..." line here - if the app's dependency jars ever change version,
|
||
|
|
# this script never needs to be updated to match.
|
||
|
|
set -u
|
||
|
|
|
||
|
|
manager_zip="${1:?Usage: check-schema-diff.sh <path-to-manager.zip>}"
|
||
|
|
stage_dir="/home/sportrum/schema-check-staging"
|
||
|
|
|
||
|
|
if [ ! -f "$manager_zip" ]; then
|
||
|
|
echo "ERROR: $manager_zip not found - has this project's webapp counterpart's \"ant release-all\" been run against this server yet?" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
rm -rf "$stage_dir"
|
||
|
|
mkdir -p "$stage_dir"
|
||
|
|
if ! unzip -q "$manager_zip" -d "$stage_dir"; then
|
||
|
|
echo "ERROR: failed to unzip $manager_zip into $stage_dir" >&2
|
||
|
|
rm -rf "$stage_dir"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
output=$(cd "$stage_dir" && bash manager-exec.sh diff-meta 2>&1)
|
||
|
|
status=$?
|
||
|
|
|
||
|
|
echo "$output"
|
||
|
|
rm -rf "$stage_dir"
|
||
|
|
|
||
|
|
if [ $status -ne 0 ]; then
|
||
|
|
echo "SCHEMA-CHECK: FAILED - manager-exec.sh exited ${status}, treat as unsafe (same as differences found)" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
if echo "$output" | grep -qF "No differences detected"; then
|
||
|
|
echo "SCHEMA-CHECK: no differences detected"
|
||
|
|
exit 0
|
||
|
|
else
|
||
|
|
echo "SCHEMA-CHECK: differences detected - see the diff above" >&2
|
||
|
|
exit 2
|
||
|
|
fi
|