#!/usr/bin/env bash # Copy the analysed demo cases and the HPO reference data into a remote database. # # The deployed demo has no Nextflow and no Docker daemon, so it cannot run VEP. Instead the cases # are annotated here, where the pipeline works, and the results are copied up. Visitors get real # analysed cases -- funnel, ranking, evidence, decisions, report -- against a database that is # never asked to produce them. # # Everything copied is derived from public, openly licensed sources (docs/data.md). There is no # patient data in this dump, and there must never be. # # scripts/seed-remote.sh "$(railway variables -s Postgres --kv | grep DATABASE_PUBLIC_URL | cut -d= -f2-)" set -euo pipefail TARGET=${1:-${TARGET_DATABASE_URL:-}} SOURCE=${SOURCE_DATABASE_URL:-postgresql://rarelens:rarelens@localhost:5432/rarelens} IMAGE=${PG_IMAGE:-postgres:16-alpine} # Reference data first, then a case's own rows: variants reference jobs, jobs reference cases. TABLES=(hpo_terms gene_phenotypes cases case_phenotypes jobs variants predictions variant_decisions) if [ -z "$TARGET" ]; then echo "usage: $0 (or set TARGET_DATABASE_URL)" >&2 echo "the target must already have the schema: run 'alembic upgrade head' against it first" >&2 exit 2 fi case "$TARGET" in postgres://*|postgresql://*) ;; *) echo "target must be a postgres:// URL, got ${TARGET%%:*}:..." >&2; exit 2 ;; esac echo "==> source: ${SOURCE%%\?*}" >&2 echo "==> target: ${TARGET%%:*}://…${TARGET##*@}" >&2 # host only: the password stays out of the log echo "==> tables: ${TABLES[*]}" >&2 # --data-only: the target's schema comes from Alembic, so the two can never disagree about it. # Truncating first makes the script repeatable; cascade because variants hang off jobs. docker run --rm -i --add-host=host.docker.internal:host-gateway \ -e PGPASSWORD_UNUSED=1 "$IMAGE" \ pg_dump --data-only --no-owner --no-privileges \ $(printf -- '--table=%s ' "${TABLES[@]}") \ "${SOURCE/localhost/host.docker.internal}" \ > /tmp/rarelens-seed.sql lines=$(wc -l < /tmp/rarelens-seed.sql) echo "==> dumped $lines lines" >&2 docker run --rm -i "$IMAGE" psql "$TARGET" -v ON_ERROR_STOP=1 \ -c "TRUNCATE $(IFS=,; echo "${TABLES[*]}") RESTART IDENTITY CASCADE" >&2 docker run --rm -i "$IMAGE" psql "$TARGET" -v ON_ERROR_STOP=1 -q < /tmp/rarelens-seed.sql rm -f /tmp/rarelens-seed.sql echo "==> loaded. counts on the target:" >&2 docker run --rm -i "$IMAGE" psql "$TARGET" -At -c " select 'cases: '||count(*) from cases union all select 'variants: '||count(*) from variants union all select 'gene_phenotypes: '||count(*) from gene_phenotypes union all select 'hpo_terms: '||count(*) from hpo_terms"