Skip to content

Segment updates#562

Merged
irees merged 4 commits intomainfrom
segment-updates
Jan 16, 2026
Merged

Segment updates#562
irees merged 4 commits intomainfrom
segment-updates

Conversation

@irees
Copy link
Copy Markdown
Contributor

@irees irees commented Jan 16, 2026

This PR enhances the segment patterns feature to enable reconstruction of map-matched shape data by adding direction, sequence, and denormalized way information to the SegmentPattern type.

Changes

Schema Updates

  • GraphQL Schema (schema.graphqls): Added new fields to SegmentPattern:
    • direction_id: Direction ID of the trip
    • sequence_idx: Sequence order of this segment within the pattern
    • shape_id: Shape ID for this segment pattern
    • way_id: OSM Way ID associated with this segment pattern
    • shape: Shape resolver for direct access to shape data
  • Deprecated Segment.way_id in favor of SegmentPattern.way_id for improved data access patterns

Database Migration

  • Added new columns to tl_segment_patterns table:
    • direction_id (integer, NOT NULL, default 0)
    • sequence_idx (integer, NOT NULL, default 0)
    • way_id (bigint, NOT NULL, populated from existing segment data)
  • Updated indexes for efficient shape reconstruction and direction-based queries

Resolvers & Model Updates

  • Added Shape resolver for SegmentPattern to load shape data via dataloader
  • Updated segment query limits to use new RESOLVER_SEGMENT_MAXLIMIT constant (100,000)
  • Added corresponding fields to SegmentPattern model struct

Test Data

  • Updated test data INSERT statements to include new columns for segment patterns

Why

These changes allow clients to reconstruct the original map-matched output for each shape by providing:

  1. The order of segments within a shape (sequence_idx)
  2. The direction of travel (direction_id)
  3. Direct access to OSM way information at the pattern level (way_id)

@irees irees marked this pull request as ready for review January 16, 2026 10:48
Copilot AI review requested due to automatic review settings January 16, 2026 10:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds schema enhancements to the segment patterns feature, enabling reconstruction of map-matched shape data by adding direction, sequence, and denormalized way information.

Changes:

  • Adds direction_id, sequence_idx, way_id, and shape fields to SegmentPattern type
  • Updates database schema with migration to add new columns and indexes to tl_segment_patterns table
  • Deprecates Segment.way_id field in favor of SegmentPattern.way_id for improved data access patterns

Reviewed changes

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

Show a summary per file
File Description
schema/postgres/migrations/20260115170510_segments_sequence_idx.up.pgsql Adds direction_id, sequence_idx, and way_id columns to tl_segment_patterns table with appropriate indexes
testdata/server/test_supplement.pgsql Updates test data INSERT statements to include new columns for segment patterns
server/model/models_gen.go Adds DirectionID, SequenceIdx, ShapeID, WayID, and Shape fields to SegmentPattern model
schema/graphql/schema.graphqls Adds new fields to SegmentPattern type and deprecates Segment.way_id
server/gql/segment_resolver.go Adds Shape resolver for SegmentPattern to load shape data via dataloader
server/gql/route_resolver.go Updates segment query limits to use RESOLVER_SEGMENT_MAXLIMIT
server/gql/resolver.go Adds RESOLVER_SEGMENT_MAXLIMIT constant for query limiting
server/finders/dbfinder/segment.go Reformats SELECT query for improved readability
internal/generated/gqlout/generated.go Generated GraphQL resolver code for new fields
gqlgen.yml Configures shape field as a resolver for SegmentPattern

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

(select id from gtfs_shapes where shape_id = '41698'),
42
42,
645693994,
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

The way_id value for segment 1418711 is inconsistent with the tl_segments table. In the tl_segments INSERT, segment 1418711 has way_id 90865590, but in this tl_segment_patterns INSERT it uses way_id 645693994. This should be 90865590 to match the segment's actual way_id.

Suggested change
645693994,
90865590,

Copilot uses AI. Check for mistakes.
@irees irees merged commit 2774e6f into main Jan 16, 2026
6 checks passed
@irees irees deleted the segment-updates branch January 16, 2026 12:07
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.

2 participants