56 lines
2.6 KiB
Bash
Executable File
56 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# =============================================================================
|
|
# The operator half: sanction installed capability schemas for use.
|
|
#
|
|
# apply-capability-streams.sh installs; this promotes. They are two scripts on two images because
|
|
# they are two decisions, and because the Flyway image ships no psql — so a promotion that lived
|
|
# inside the migration step could not have run at all, which is how this split was found.
|
|
#
|
|
# Promotion is an UPDATE rather than a migration on purpose. A stream that promoted itself would make
|
|
# "the tables exist" and "an operator sanctioned this capability" indistinguishable, and the second is
|
|
# the one NotificationSchemaActivation refuses to start without.
|
|
#
|
|
# CAPABILITY_STREAMS is a space-separated list of directory names under db/migration/jpa; the ids are
|
|
# mapped explicitly below because they are not derivable from the directory names.
|
|
# =============================================================================
|
|
set -eu
|
|
|
|
: "${PGHOST:?PGHOST is required}"
|
|
: "${PGUSER:?PGUSER is required}"
|
|
: "${PGDATABASE:?PGDATABASE is required}"
|
|
: "${CAPABILITY_STREAMS:=}"
|
|
|
|
promote() {
|
|
capability="$1"
|
|
echo "capability-streams: promoting ${capability}"
|
|
# A promotion that matched no row would leave the capability inactive and be reported as success,
|
|
# so the row count is checked rather than the exit status. That failure mode is the whole reason
|
|
# this step exists: it would surface much later as a startup refusal about a capability the lane
|
|
# believed it had promoted.
|
|
updated="$(psql -v ON_ERROR_STOP=1 -qtAX -h "${PGHOST}" -U "${PGUSER}" -d "${PGDATABASE}" -c \
|
|
"update capability_schema_registry set lifecycle_state = 'ACTIVE'
|
|
where capability_id = '${capability}' returning capability_id" | wc -l)"
|
|
if [ "${updated}" -ne 1 ]; then
|
|
echo "capability-streams: ${capability} is not installed; nothing was promoted" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
promote jpa-flyway-migration
|
|
|
|
# Capability ids are not derivable from directory names — jpa/notification-platform registers
|
|
# jpa-notification-platform-v4 — so each stream a lane asks for is named here rather than guessed. An
|
|
# unmapped stream fails loudly instead of being installed and left inactive.
|
|
for stream in ${CAPABILITY_STREAMS}; do
|
|
case "${stream}" in
|
|
notification-platform) promote jpa-notification-platform-v4 ;;
|
|
fileserver) promote jpa-fileserver-metadata-v1 ;;
|
|
*)
|
|
echo "capability-streams: no promotion mapping for stream '${stream}'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
echo "capability-streams: promoted core [${CAPABILITY_STREAMS}]"
|