Skip to content

feat(substations): power_plant_interconnections join table + sync (PR 7/9)#200

Merged
texture-fleet-agent[bot] merged 4 commits intomainfrom
meridian/substations-power-plant-joins
May 6, 2026
Merged

feat(substations): power_plant_interconnections join table + sync (PR 7/9)#200
texture-fleet-agent[bot] merged 4 commits intomainfrom
meridian/substations-power-plant-joins

Conversation

@texture-fleet-agent
Copy link
Copy Markdown
Contributor

Part of the substations 9th entry point epic.

Adds power_plant_interconnections join table linking power plants to their substation(s), plus a sync script that picks the closest/most-likely substation for each plant (with distance + is_primary flag).

Stack: PR 7/9 (base: previous [PR 6 transmission joins])

Completes the substation ↔ grid asset graph: plants → substations → transmission lines.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
commongrid Ready Ready Preview, Comment May 6, 2026 5:59pm

Request Review

texture-coding-agent and others added 3 commits May 6, 2026 15:16
…c (PR 6/9)

Implements transmission_line_endpoints join table to replace fuzzy sub1/sub2
string references with formal foreign keys. Includes fuzzy matching sync script
with confidence scoring for community review workflow.

**What's included:**
- Schema: transmission_line_endpoints table with role (from|to) and match_confidence
- Migration: 0005_transmission_line_endpoints.sql with indexes
- Sync script: fuzzy-matches transmission_lines.sub1/sub2 against substation names
- Levenshtein + suffix-variation matching for reliability
- Match confidence (0..1) for high/medium/low confidence filtering

**Features:**
- Auto-matches high-confidence pairs (≥0.85)
- Flags lower-confidence for community review
- Handles common suffix variations (SUBSTATION/STATION/SUB)
- Batch insert with upsert support

**Next:**
- PR #7: power_plant_interconnections join + sync
- PR #8: Join query API endpoints
- PR #9: Docs + catalog

---
*Part of CommonGrid 9th entry point milestone (substations) — PR 6 of 9*
…nc (PR 7/9)

Implements power_plant_interconnections join table to link power plants to their
nearest substation(s) for grid interconnection analysis. Uses PostGIS ST_Distance
to compute spatial relationships.

**What's included:**
- Schema: power_plant_interconnections table with distance_meters and isPrimary
- Migration: 0006_power_plant_interconnections.sql with optimized indexes
- Sync script: ST_Distance-based spatial matching via PostGIS
- Configurable search radius (default: 50 km via SEARCH_RADIUS_KM env var)
- Primary + secondary interconnection candidates

**Features:**
- Efficiently computes nearest substation per power plant
- Marks closest match as isPrimary=true
- Stores all candidates within search radius
- Distance in meters for precise filtering
- Batch insert with upsert support

**Next:**
- PR #8: Join query API endpoints
- PR #9: Docs + catalog

---
*Part of CommonGrid 9th entry point milestone (substations) — PR 7 of 9*
* feat(substations): add join query API endpoints (PR 8/9)

Adds API endpoints to query the join tables:
- GET /api/v1/substations/[slug]/transmission-lines
- GET /api/v1/power-plants/[slug]/substations

**What's included:**
- Substation → transmission lines endpoint (lists connected lines + confidence)
- Power plant → interconnected substations endpoint (primary + secondaries)
- Distance metrics in km for power plant interconnections
- Confidence distribution statistics for transmission line matches
- Cache headers (3600s public)

**Features:**
- Groups transmission lines by role (from/to)
- Separates primary interconnection from secondaries
- Includes match confidence for community review
- Efficient queries with proper joins

**Next:**
- PR #9: Docs + catalog update

---
*Part of CommonGrid 9th entry point milestone (substations) — PR 8 of 9*

* fix(cron): cap sync-substations maxDuration at 800s (Vercel Pro limit)

Vercel Pro plan enforces a max of 800 seconds for serverless function
maxDuration. The previous 1800s value caused the build to succeed but
deployment to fail at the patchBuild step with:

  Builder returned invalid maxDuration value for Serverless Function
  "api/cron/sync-substations". Serverless Functions must have a
  maxDuration between 1 and 800 for plan pro.

Capping at 800 unblocks deploys. Full US substation syncs that exceed
this should be moved to a long-running runner (GitHub Actions, Render,
etc.) rather than a Vercel serverless function.

---------

Co-authored-by: texture-coding-agent <coding-agent@texturehq.com>
@texture-fleet-agent texture-fleet-agent Bot merged commit cbc4fea into main May 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant