Replace flag-based upgrade.sh with named migrate/hotfix-code modes
upgrade.sh's old -f/-w/-s flags let you skip a backup or the DB
migration independently of each other, with nothing to stop a
combination that didn't actually make sense for the change being
shipped. Replace them with two named modes:
- migrate: for a change that touches the DB. Full SQL+WAR+logs
backup, both the existing short-lived tier and a new, never-pruned
backup/migrations/<tag>/ tier (before/after snapshot plus the full
DB migration transcript, tee'd from manager-exec.sh). The tag comes
from build.xml's migrate(@host) target: the git version already
embedded in sportrum.war's WEB-INF/VERSION (see README for the
webapp project's own build.xml snippet this needs), plus an
optional interactive label via Ant's <input> task.
- hotfix-code: for a Java/resource change with no DB migration. WAR
backup only (no SQL dump, no indefinite copy), no manager-exec.sh
at all. Only reached after check-schema-diff.sh - a new script that
runs ICPManager's diff-meta against a staged, not-yet-installed
copy of manager.zip, entirely independent of the live webapp/Tomcat
- has already confirmed there's no pending schema change, hard
gating build.xml's hotfix-code(@host) target before Tomcat is ever
touched.
A third scenario (template-only hotfix, no Tomcat restart at all) is
intentionally not implemented yet - which files count as "templates"
and how they'd sync into the live webapp directory is still an open
question.
Dropped without replacement: the old storeonly (-s) mode and the
"leave Tomcat stopped" action argument - undocumented, flag-only
behaviors nothing here exercised, easy to reintroduce as an explicit
mode later if actually needed.
Also fixes a real gap found while testing this: a failed migration
left upgrade-cmds.sh exiting 0, which would have made upgrade.sh (and
an Ant sshexec with failonerror) report success on a failed DB
migration. And build.xml's deploy.key.passphrase had no default,
which (confirmed by testing) left the literal string
"${deploy.key.passphrase}" as the passphrase for anyone not setting
it in build.local.properties.
Verified with a full fake fixture (fake pg_dump, fake manager.zip/
manager-exec.sh, fake sportrum.war): migrate success, migrate
collision-refusal on a reused tag, migrate failure preserving the
before-snapshot without pruning, hotfix-code skipping the SQL/DB
steps, and check-schema-diff.sh's three exit codes (clean/
differences/broken) all behave as designed. Ant-side tag assembly
(<input> skip-when-preset, blank-label fallback, unsafe-character
rejection) verified the same way.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
2026-09-30 20:00:35 +00:00
|
|
|
#!/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
|
|
|
|
|
|
2026-09-30 20:17:35 +00:00
|
|
|
# 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)
|
Replace flag-based upgrade.sh with named migrate/hotfix-code modes
upgrade.sh's old -f/-w/-s flags let you skip a backup or the DB
migration independently of each other, with nothing to stop a
combination that didn't actually make sense for the change being
shipped. Replace them with two named modes:
- migrate: for a change that touches the DB. Full SQL+WAR+logs
backup, both the existing short-lived tier and a new, never-pruned
backup/migrations/<tag>/ tier (before/after snapshot plus the full
DB migration transcript, tee'd from manager-exec.sh). The tag comes
from build.xml's migrate(@host) target: the git version already
embedded in sportrum.war's WEB-INF/VERSION (see README for the
webapp project's own build.xml snippet this needs), plus an
optional interactive label via Ant's <input> task.
- hotfix-code: for a Java/resource change with no DB migration. WAR
backup only (no SQL dump, no indefinite copy), no manager-exec.sh
at all. Only reached after check-schema-diff.sh - a new script that
runs ICPManager's diff-meta against a staged, not-yet-installed
copy of manager.zip, entirely independent of the live webapp/Tomcat
- has already confirmed there's no pending schema change, hard
gating build.xml's hotfix-code(@host) target before Tomcat is ever
touched.
A third scenario (template-only hotfix, no Tomcat restart at all) is
intentionally not implemented yet - which files count as "templates"
and how they'd sync into the live webapp directory is still an open
question.
Dropped without replacement: the old storeonly (-s) mode and the
"leave Tomcat stopped" action argument - undocumented, flag-only
behaviors nothing here exercised, easy to reintroduce as an explicit
mode later if actually needed.
Also fixes a real gap found while testing this: a failed migration
left upgrade-cmds.sh exiting 0, which would have made upgrade.sh (and
an Ant sshexec with failonerror) report success on a failed DB
migration. And build.xml's deploy.key.passphrase had no default,
which (confirmed by testing) left the literal string
"${deploy.key.passphrase}" as the passphrase for anyone not setting
it in build.local.properties.
Verified with a full fake fixture (fake pg_dump, fake manager.zip/
manager-exec.sh, fake sportrum.war): migrate success, migrate
collision-refusal on a reused tag, migrate failure preserving the
before-snapshot without pruning, hotfix-code skipping the SQL/DB
steps, and check-schema-diff.sh's three exit codes (clean/
differences/broken) all behave as designed. Ant-side tag assembly
(<input> skip-when-preset, blank-label fallback, unsafe-character
rejection) verified the same way.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
2026-09-30 20:00:35 +00:00
|
|
|
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
|