sportrum-deploy/check-schema-diff.sh
Claude 72b159c997
Fix check-schema-diff.sh: manager.zip nests under manager/, not flat
The webapp project's real manager-zip target (seen for the first time
this round) zips "manager/**/*" out of its build dir, so
manager-exec.sh/manager.conf/model/libs all live under one manager/
prefix inside the zip - not at its root. check-schema-diff.sh did
"cd $stage_dir && bash manager-exec.sh", which only worked against my
own hand-built test fixture because I'd zipped that one flat by
mistake; against a real manager.zip it would have failed to find
manager-exec.sh at all. Fixed to cd into $stage_dir/manager, with a
defensive check that fails loudly (rather than a bare "No such file
or directory" from cd) if that layout is ever wrong.

Re-verified all four check-schema-diff.sh scenarios (clean/dirty/
broken/missing) against a correctly-nested fixture this time, plus
the new defensive check against a deliberately flat/malformed zip.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
2026-09-30 20:17:35 +00:00

75 lines
3 KiB
Bash
Executable file

#!/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
# manager.zip's own build target (the webapp project's manager-zip, which
# zips "manager/**/*" out of its build dir) nests everything under one
# manager/ directory - manager-exec.sh, manager.conf, model/, and libs/ all
# live there, not at the zip's root.
if [ ! -f "$stage_dir/manager/manager-exec.sh" ]; then
echo "ERROR: $manager_zip didn't unzip to the expected manager/manager-exec.sh - has its layout changed?" >&2
rm -rf "$stage_dir"
exit 1
fi
output=$(cd "$stage_dir/manager" && 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