Skip to content

add stops.stop_access field#504

Merged
irees merged 10 commits into
mainfrom
stop-access
Jun 18, 2026
Merged

add stops.stop_access field#504
irees merged 10 commits into
mainfrom
stop-access

Conversation

@drewda

@drewda drewda commented Sep 23, 2025

Copy link
Copy Markdown
Member

Summary

Adds the stops.stop_access field (GTFS proposal google/transit#515, closing tlv2#204) end-to-end: parsing and validation on the Stop entity, storage in both the raw and materialized stop tables (Postgres and SQLite), the materialization projection, the read path, GraphQL (both the Stop type and the stop edit mutation), and REST, with unit and mutation tests. This supersedes the original scope of this PR, which only parsed/validated/stored the field without exposing it.

transitland-lib#504 — spec: google/transit#515

Field and validation (gtfs/stop.go)

Adds StopAccess tt.Int with enum:"0,1" to the Stop struct. With no explicit csv:/db: tag it maps to the stop_access CSV and DB column by the standard snake_case reflection, same as the adjacent LevelID/level_id, so the import write path persists it with no extra wiring.
Per the spec, 0 means the platform must be reached via a station entrance/pathways, 1 means directions may route directly to the stop, and empty means undefined.
ConditionalErrors() enforces that stop_access is only valid on a platform (location_type 0) that has a parent_station: it flags an InvalidFieldError when location_type != 0, or (else) when parent_station is empty. The else if reports a single error rather than two when both conditions hold (e.g. a station). The enum:"0,1" tag independently rejects out-of-range values.
Both the enum and conditional rules run on every write path, including the GraphQL mutation: createUpdateEnt calls tt.CheckErrors before insert/update, so an invalid stop_access cannot be persisted.

Storage and schema

New Postgres migration 20260617000002_add_stop_access.up.pgsql adds a nullable stop_access integer column to both gtfs_stops and the materialized tl_materialized_active_stops. Up-only, additive, backward compatible, consistent with the repo's migration convention (no .down files exist). It is numbered 000002 so it orders after 20260617000001_trip_safe_duration, which arrived on this branch via the merge from main.
schema/sqlite/sqlite.sql (hand-maintained) adds the matching stop_access integer column to both gtfs_stops and tl_materialized_active_stops.
internal/feedstate/manager.go adds stop_access to the stop projection map so the value propagates from gtfs_stops into tl_materialized_active_stops during materialization.

Read path and API exposure

server/finders/dbfinder/stop.go adds gtfs_stops.stop_access to the stopSelect column list, which reads from either gtfs_stops or the aliased tl_materialized_active_stops.
schema/graphql/schema.graphqls adds stop_access: Int to type Stop. It autobinds to the embedded gtfs.Stop.StopAccess (no resolver needed); the generated gqlgen runtime is regenerated.
REST exposes the field via the stop_request.gql and stop_departure_request.gql selection sets; doc/openapi/rest.json is regenerated (the large diff is the deterministic x-order renumbering plus the new field — no other changes).

Mutations

stop_access: Int is added to input StopSetInput, and createUpdateStop scans it into the entity, so the field is settable through the stop_create / stop_update mutations alongside the other editable platform attributes. The generated input model is regenerated.

Tests

gtfs/stop_test.go adds validation cases: valid stop_access 0/1 on a platform with a parent, forbidden on an entrance and on a parentless platform, and a station case asserting a single error (which guards the else if).
server/gql/entity_mutation_resolver_test.go extends TestStopCreate to create a parent station, set stop_access through the stop mutation, and assert the value round-trips back from the database.

Migration

Required. Deploying this runs dbmigrate up to add gtfs_stops.stop_access and tl_materialized_active_stops.stop_access (and tlv2 dbmigrate up when this pin is later picked up by tlv2). Additive and backward compatible; existing materialized rows pick up the value on the next materialization.

Test plan

go build ./... and go test ./... (CI).
Import a feed whose stops.txt sets stop_access to 0/1 on platforms with a parent_station; confirm the values land in gtfs_stops.stop_access and surface via the GraphQL Stop.stop_access field and the REST stop and stop-departures endpoints.
Set stop_access via the stop_create/stop_update GraphQL mutation on a platform with a parent and confirm it persists.
Confirm validation rejects stop_access on a station, on a parentless stop, and any value outside {0,1}, on both import and the mutation path.

@irees irees marked this pull request as ready for review June 18, 2026 00:55
Copilot AI review requested due to automatic review settings June 18, 2026 00:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for the proposed GTFS stops.stop_access field to Transitland’s GTFS ingestion pipeline so it can be parsed/validated and persisted to storage (Postgres + SQLite schemas), without exposing it via APIs yet.

Changes:

  • Adds StopAccess to the GTFS Stop entity with enum validation (0,1) and conditional validation rules in ConditionalErrors().
  • Adds stop_access column to gtfs_stops in the SQLite schema.
  • Adds a Postgres migration to add nullable gtfs_stops.stop_access.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
gtfs/stop.go Adds StopAccess field and conditional validation rules for allowed usage.
schema/sqlite/sqlite.sql Adds stop_access column to gtfs_stops for SQLite-backed workflows.
schema/postgres/migrations/20260617000002_add_stop_access.up.pgsql Adds migration to add nullable stop_access column to Postgres gtfs_stops.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gtfs/stop.go Outdated
Comment thread gtfs/stop.go Outdated
@irees irees merged commit 6db6f46 into main Jun 18, 2026
6 checks passed
@irees irees deleted the stop-access branch June 18, 2026 02:10
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.

3 participants