Skip to content

Commit 679a385

Browse files
authored
fix: Port tenant provisioning reset fixes to deploy-demo workflow (#2134)
The demo deploy had the same broken reset as develop had before PRs #2131 and #2133: - Only reset tenant_provisioning.state, not tenant.status (worker polls tenant.status via ListByStatus(StatusProvisioningPending)) - Didn't clear service_schemas JSONB (provisioner short-circuits on "service already provisioned, skipping") - Didn't drop ghost schemas from previous broken runs - Didn't stop the app before resetting (race between worker and schema drops) Port the same fix from deploy-develop.yml: - Stop meridian before resetting state - DROP SCHEMA CASCADE for org_* schemas across all service databases - Reset both tenant.status and tenant_provisioning.service_schemas - Start meridian after reset Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent f818796 commit 679a385

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

.github/workflows/deploy-demo.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,46 @@ jobs:
267267
username: deploy
268268
key: ${{ secrets.DEPLOY_SSH_KEY }}
269269
script: |
270-
# If any tenant has stale "active" status but missing schemas (e.g. after
271-
# new databases were created), reset to "pending" so the provisioner
272-
# re-creates schemas. Must run AFTER migrations so the provisioner has
273-
# up-to-date DDL. Safe when schemas already exist (CREATE SCHEMA IF NOT EXISTS).
274-
docker exec meridian-postgres-1 psql -U meridian -d meridian_platform -c \
275-
"UPDATE tenant_provisioning SET state = 'pending' WHERE state IN ('active', 'failed')"
270+
cd /opt/meridian
271+
# Stop the app before resetting state. The provisioning worker
272+
# polls tenant.status every 10s - if still running when we flip
273+
# tenants to provisioning_pending it races with the schema drops
274+
# below. Stopping first eliminates the race.
275+
docker compose stop meridian
276+
277+
# Drop tenant schemas across all service databases so migrations
278+
# run against completely empty schemas. Ghost state from previous
279+
# broken runs (renamed tables, partial objects) causes migrations
280+
# to fail with "relation does not exist". Matches the E2E path.
281+
SERVICE_DBS="meridian_party meridian_current_account meridian_position_keeping meridian_financial_accounting meridian_payment_order meridian_market_information meridian_reference_data meridian_internal_account meridian_reconciliation meridian_identity meridian_control_plane"
282+
for DB in $SERVICE_DBS; do
283+
docker exec meridian-postgres-1 psql -U meridian -d $DB -tA -c "
284+
SELECT format('DROP SCHEMA IF EXISTS %I CASCADE', nspname)
285+
FROM pg_namespace WHERE nspname LIKE 'org\_%' ESCAPE '\\'
286+
" | while read stmt; do
287+
[ -z "$stmt" ] && continue
288+
docker exec meridian-postgres-1 psql -U meridian -d $DB -c "$stmt"
289+
done
290+
done
291+
292+
# Reset both tables in tandem:
293+
# - tenant.status: the provisioning worker polls this via
294+
# ListByStatus(StatusProvisioningPending). Without resetting,
295+
# the worker never claims the tenant for re-provisioning.
296+
# - tenant_provisioning.service_schemas: the provisioner checks
297+
# this per-service and short-circuits via "service already
298+
# provisioned, skipping" if marked 'migrated'. Clearing to
299+
# '[]' forces a full re-run.
300+
# Must run AFTER migrations so the provisioner uses up-to-date DDL.
301+
docker exec meridian-postgres-1 psql -U meridian -d meridian_platform -c "
302+
UPDATE tenant SET status = 'provisioning_pending', updated_at = NOW() WHERE status != 'deprovisioned';
303+
UPDATE tenant_provisioning SET state = 'pending', service_schemas = '[]'::jsonb, error_message = '' WHERE state != 'deprovisioned';
304+
"
305+
306+
# Start the app back up with reset state in place. The worker
307+
# will claim pending tenants on its first poll and re-run all
308+
# migrations against the newly empty schemas.
309+
docker compose start meridian
276310
277311
- name: Bootstrap master tenant
278312
uses: appleboy/ssh-action@0ff4204d59e8e51228ff73bce53f80d53301dee2 # v1.2.5

0 commit comments

Comments
 (0)