Region Setup & Seeding Guide
Unified seed guide: how to run seeds, migration order, market-pack inventory, RUDS config.
4 min read diagramsUpdated 2026-06-03docs/ai-seed-guide.md
Quick Reference
# One-command region seed (runs ALL seeds for a region):
cd infrastructure && ./deploy.sh <region> seed
# Regions: japan | philippines | thailand | china
How It Works
Each region has a market pack at infrastructure/market-packs/medos-<region>/ containing:
| File | Purpose |
|---|---|
manifest.json |
Region metadata: country_code, locale, timezone, currency, seeds[], scripts[] |
seed-*.sql |
Supabase SQL seeds (run via supabase db query --linked -f) |
seed-*.ts |
TypeScript seeds (run via npx tsx with frontend env) |
seed-*.js |
MongoDB seeds (run via mongosh) |
deploy.sh seed reads the manifest and executes all seed files automatically.
When to Run Seeds
Run seeds after ANY of these:
- New region deployment —
./deploy.sh <region> seed - New Supabase migration that adds seed-dependent tables — re-run the relevant market pack seed
- Switching a deployment’s region — run the new region’s seeds (additive, won’t delete existing data)
Manual Seed Execution (When deploy.sh Isn’t Available)
SQL seeds (Supabase)
# Prerequisite: supabase CLI logged in + project linked
# Check: supabase projects list
# Run a single seed file:
supabase db query --linked -f infrastructure/market-packs/medos-<region>/seed-<name>.sql
# Run ALL SQL seeds for a region:
for sql in infrastructure/market-packs/medos-<region>/seed-*.sql; do
echo "Running $(basename "$sql")..."
supabase db query --linked -f "$sql"
done
TypeScript seeds (Supabase via JS client)
cd web
cp .env.<region> .env # or .env.vercel.<locale>
npx tsx ../infrastructure/market-packs/medos-<region>/seed-<name>.ts
Supabase migrations (not seeds, but often needed alongside)
# Run a specific migration:
supabase db query --linked -f infrastructure/medbase/migrations/<migration>.sql
# Run ALL migrations in order:
for sql in infrastructure/medbase/migrations/*.sql; do
echo "Running $(basename "$sql")..."
supabase db query --linked -f "$sql"
done
Edge functions
cd infrastructure/medbase
supabase functions deploy <function-name> --no-verify-jwt
Seed Dependency Order
Some seeds depend on migrations being applied first. Follow this order:
1. Supabase migrations (infrastructure/medbase/migrations/*.sql)
└── Creates tables, RLS policies, triggers, functions
2. Base seed rules (already in migrations, e.g. 20260522c seeds detection_rules)
3. Market pack SQL seeds (infrastructure/market-packs/medos-<region>/seed-*.sql)
└── Region-specific overrides, config values, locale data
4. Market pack TS seeds (infrastructure/market-packs/medos-<region>/seed-*.ts)
└── Complex seeds that use Supabase JS client
5. MongoDB seeds if applicable
RUDS (Rogue User Detection) Config
RUDS uses a ruds_config table for deployment-level settings. The key config:
| Key | Purpose | Set By |
|---|---|---|
home_country |
ISO country code of this deployment. Login from any other country triggers detection. | Market pack seed (seed-ruds-rules.sql) |
allowed_neighbor_countries |
Countries considered “local” for geo rules | Market pack seed |
Each market pack’s seed-ruds-rules.sql auto-sets home_country from the manifest’s country_code:
| Region | home_country |
allowed_neighbor_countries |
|---|---|---|
| Philippines | PH |
PH, SG |
| Japan | JP |
JP, KR, TW |
| Thailand | TH |
TH, LA, MM, KH, MY |
No manual config needed — just run the region’s seeds.
Adding Seeds for a New Module
When you create a new module that needs per-region seed data:
- Add SQL seed file to EACH market pack:
infrastructure/market-packs/medos-<region>/seed-<module>.sql - Make it idempotent (
ON CONFLICT DO NOTHINGorWHERE NOT EXISTS) - Make it bilingual (local language + English columns)
- Add the filename to the manifest’s
seedsarray (optional —deploy.shruns allseed-*.sqlregardless) - Test:
supabase db query --linked -f <your-seed>.sql
Current Market Pack Inventory
medos-philippines
seed-hospital-facility.sql— PH hospital master dataseed-ipd-wards.sql— IPD ward configurationseed-philhealth-rates.sql— PhilHealth insurance case ratesseed-pathology-filipino.sql— Pathology catalog (Filipino + English)seed-ruds-rules.sql— RUDS config (home_country=PH) + rule overrides
medos-japan
seed-hospital-facility.sql— JP hospital master dataseed-ipd-wards.sql— IPD ward configurationseed-kaigo-rates.sql— Long-Term Care Insurance ratesseed-pathology-japanese.sql— Pathology catalog (Japanese + English)seed-honobono-parity-mocks.sql— Honobono system parity mocksseed-ruds-rules.sql— RUDS config (home_country=JP) + rule overrides
medos-thailand
- Seeds are mostly in
web/supabase/migrations/(original/default data) seed-ruds-rules.sql— RUDS config (home_country=TH)- Various domain-specific seeds (blood bank, NHSO, imaging, etc.)
medos-china
seed-hospital-facility.sql— CN hospital master data (北京和睦家, bilingual zh/en)seed-ipd-wards.sql— IPD ward configuration (bilingual)seed-china-insurers.sql— commercial + international insurers + GOP policies (Bupa/Cigna/MSH/Allianz/AXA/Ping An/PICC + 社保)seed-terminology-cn.sql— ICD-10-CN stub +name_zhon pathology mastersseed-ruds-home-country.sql— RUDS geo baseline (home_country=CN). Apply AFTER20260524_ruds_config.sql; NOT in manifestseeds[](order-dependent)fapiao-template.json— 增值税电子普通发票 (Fapiao) template (config, not a SQL seed)- Connector packs:
eclaim-connector/connector-packs/{cn-commercial-direct,cn-shebao-basic}.json(schemesCN_COMMERCIAL/CN_SHEBAO) - Migrations:
20260602b_gold_rollout_kpi.sql,20260602d_booking_waitlist.sql,20260602e_doctor_efficiency.sql - Compliance:
docs/architecture/china-pipl-dsl-compliance.md(PIPL/DSL/CSL + MLPS-2.0; read-model-residency is a Phase-0 gate) - Rollout runbook:
infrastructure/market-packs/medos-china/README.md· build logdocs/uat/medos-china-build-log.md
Troubleshooting
| Problem | Fix |
|---|---|
supabase db query fails with auth error |
Run supabase login to refresh token |
| Migration fails on missing table | Run prerequisites first (check migration filename order) |
| Seed fails with conflict | Already applied — seeds are idempotent, safe to skip |
deploy.sh doesn’t know region |
Add case block in deploy.sh (lines 26-55) |
| Edge function deploy fails | cd infrastructure/medbase first (needs supabase/config.toml) |