Skip to content

Add DB table to store GTFS feed availability checks #1700

@davidgamez

Description

@davidgamez

Description

Availability should be derived from historical request attempts. It should not be stored directly on the feed or returned in the standard feed response.

Proposed solution

CREATE TABLE gtfsfeedavailabilitycheck (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),

    feed_id VARCHAR(255) NOT NULL,
    checked_at TIMESTAMPTZ NOT NULL DEFAULT now(),

    request_url TEXT NOT NULL,
    status_code INTEGER,
    latency_ms DOUBLE PRECISION,

    error_message TEXT,
    error_type VARCHAR(255),

    success BOOLEAN NOT NULL,

    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),

    CONSTRAINT gtfsfeedavailabilitycheck_feed_id_fkey
        FOREIGN KEY (feed_id)
        REFERENCES gtfsfeed(id)
        ON DELETE CASCADE
);

CREATE INDEX idx_gtfsfeedavailabilitycheck_feed_checked_at
    ON gtfsfeedavailabilitycheck (feed_id, checked_at DESC);

CREATE INDEX idx_gtfsfeedavailabilitycheck_checked_at
    ON gtfsfeedavailabilitycheck (checked_at DESC);

CREATE INDEX idx_gtfsfeedavailabilitycheck_feed_success_checked_at
    ON gtfsfeedavailabilitycheck (feed_id, success, checked_at DESC);

I would keep success even if it can be inferred from status_code, because it makes queries and chart aggregation easier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions