Skip to content

Commit

Permalink
Add route direction.
Browse files Browse the repository at this point in the history
  • Loading branch information
jarkkoka committed Sep 5, 2023
1 parent 53bde64 commit 347e713
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---------- Drop columns from Journey Pattern Ref ----------

ALTER TABLE journey_pattern.journey_pattern_ref
DROP COLUMN route_validity_end;

Expand All @@ -9,3 +11,7 @@ ALTER TABLE journey_pattern.journey_pattern_ref

ALTER TABLE journey_pattern.journey_pattern_ref
DROP COLUMN route_label;

---------- Drop table Route Direction ----------

DROP TABLE route.direction;
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
---------- Add Route Direction ----------

CREATE TABLE route.direction (
direction text NOT NULL,
the_opposite_of_direction text
);

COMMENT ON TABLE route.direction IS 'The route directions from Transmodel';
COMMENT ON COLUMN route.direction.direction IS 'The name of the route direction';
COMMENT ON COLUMN route.direction.the_opposite_of_direction IS 'The opposite direction';

ALTER TABLE route.direction
ADD CONSTRAINT direction_pkey PRIMARY KEY (direction);
ALTER TABLE route.direction
ADD CONSTRAINT direction_the_opposite_of_direction_fkey
FOREIGN KEY (the_opposite_of_direction) REFERENCES route.direction(direction);

CREATE INDEX idx_direction_the_opposite_of_direction ON route.direction USING btree (the_opposite_of_direction);

INSERT INTO route.direction (direction, the_opposite_of_direction)
VALUES
('inbound', 'outbound'),
('outbound', 'inbound'),
('clockwise', 'anticlockwise'),
('anticlockwise', 'clockwise'),
('northbound', 'southbound'),
('southbound', 'northbound'),
('eastbound', 'westbound'),
('westbound', 'eastbound')
ON CONFLICT (direction)
DO UPDATE SET the_opposite_of_direction = EXCLUDED.the_opposite_of_direction;

---------- Add new columns to Journey Pattern Ref ----------

ALTER TABLE journey_pattern.journey_pattern_ref
ADD COLUMN route_label text NOT NULL;

Expand All @@ -14,3 +48,9 @@ COMMENT ON COLUMN journey_pattern.journey_pattern_ref.route_label IS 'The label
COMMENT ON COLUMN journey_pattern.journey_pattern_ref.route_direction IS 'The direction of the route associated with the referenced journey pattern';
COMMENT ON COLUMN journey_pattern.journey_pattern_ref.route_validity_start IS 'The start date of the validity period of the route associated with the referenced journey pattern. If NULL, then the start of the validity period is unbounded (-infinity).';
COMMENT ON COLUMN journey_pattern.journey_pattern_ref.route_validity_end IS 'The end date of the validity period of the route associated with the referenced journey pattern. If NULL, then the end of the validity period is unbounded (infinity).';

ALTER TABLE journey_pattern.journey_pattern_ref
ADD CONSTRAINT journey_pattern_ref_route_direction_fkey
FOREIGN KEY (route_direction) REFERENCES route.direction(direction);

CREATE INDEX idx_journey_pattern_ref_route_direction ON journey_pattern.journey_pattern_ref USING btree (route_direction);
63 changes: 63 additions & 0 deletions migrations/timetablesdb-dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,30 @@ COMMENT ON TRIGGER queue_validate_passing_times_sequence_on_pt_update_trigger ON
COMMENT ON TRIGGER validate_passing_times_sequence_trigger ON passing_times.timetabled_passing_time IS 'Trigger to validate the passing time <-> stop point sequence after modifications on the passing time table.
This trigger will cause those vehicle journeys to be checked, whose ID was queued to be checked by a statement level trigger.';

--
-- Name: COLUMN direction.direction; Type: COMMENT; Schema: route; Owner: dbhasura
--

COMMENT ON COLUMN route.direction.direction IS 'The name of the route direction';

--
-- Name: COLUMN direction.the_opposite_of_direction; Type: COMMENT; Schema: route; Owner: dbhasura
--

COMMENT ON COLUMN route.direction.the_opposite_of_direction IS 'The opposite direction';

--
-- Name: COLUMN type_of_line.type_of_line; Type: COMMENT; Schema: route; Owner: dbhasura
--

COMMENT ON COLUMN route.type_of_line.type_of_line IS 'GTFS route type: https://developers.google.com/transit/gtfs/reference/extended-route-types';

--
-- Name: TABLE direction; Type: COMMENT; Schema: route; Owner: dbhasura
--

COMMENT ON TABLE route.direction IS 'The route directions from Transmodel';

--
-- Name: TABLE type_of_line; Type: COMMENT; Schema: route; Owner: dbhasura
--
Expand Down Expand Up @@ -714,6 +732,13 @@ ALTER TABLE ONLY journey_pattern.journey_pattern_ref
ALTER TABLE ONLY passing_times.timetabled_passing_time
ADD CONSTRAINT timetabled_passing_time_pkey PRIMARY KEY (timetabled_passing_time_id);

--
-- Name: direction direction_pkey; Type: CONSTRAINT; Schema: route; Owner: dbhasura
--

ALTER TABLE ONLY route.direction
ADD CONSTRAINT direction_pkey PRIMARY KEY (direction);

--
-- Name: type_of_line type_of_line_pkey; Type: CONSTRAINT; Schema: route; Owner: dbhasura
--
Expand Down Expand Up @@ -803,6 +828,13 @@ CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;

CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;

--
-- Name: journey_pattern_ref journey_pattern_ref_route_direction_fkey; Type: FK CONSTRAINT; Schema: journey_pattern; Owner: dbhasura
--

ALTER TABLE ONLY journey_pattern.journey_pattern_ref
ADD CONSTRAINT journey_pattern_ref_route_direction_fkey FOREIGN KEY (route_direction) REFERENCES route.direction(direction);

--
-- Name: journey_pattern_ref journey_pattern_ref_type_of_line_fkey; Type: FK CONSTRAINT; Schema: journey_pattern; Owner: dbhasura
--
Expand All @@ -824,6 +856,13 @@ ALTER TABLE ONLY passing_times.timetabled_passing_time
ALTER TABLE ONLY passing_times.timetabled_passing_time
ADD CONSTRAINT timetabled_passing_time_vehicle_journey_id_fkey FOREIGN KEY (vehicle_journey_id) REFERENCES vehicle_journey.vehicle_journey(vehicle_journey_id);

--
-- Name: direction direction_the_opposite_of_direction_fkey; Type: FK CONSTRAINT; Schema: route; Owner: dbhasura
--

ALTER TABLE ONLY route.direction
ADD CONSTRAINT direction_the_opposite_of_direction_fkey FOREIGN KEY (the_opposite_of_direction) REFERENCES route.direction(direction);

--
-- Name: day_type_active_on_day_of_week day_type_active_on_day_of_week_day_type_id_fkey; Type: FK CONSTRAINT; Schema: service_calendar; Owner: dbhasura
--
Expand Down Expand Up @@ -1616,6 +1655,12 @@ ALTER FUNCTION vehicle_service.refresh_journey_patterns_in_vehicle_service() OWN

CREATE INDEX idx_journey_pattern_ref_journey_pattern_id ON journey_pattern.journey_pattern_ref USING btree (journey_pattern_id);

--
-- Name: idx_journey_pattern_ref_route_direction; Type: INDEX; Schema: journey_pattern; Owner: dbhasura
--

CREATE INDEX idx_journey_pattern_ref_route_direction ON journey_pattern.journey_pattern_ref USING btree (route_direction);

--
-- Name: journey_pattern_ref_type_of_line; Type: INDEX; Schema: journey_pattern; Owner: dbhasura
--
Expand All @@ -1634,6 +1679,12 @@ CREATE INDEX idx_timetabled_passing_time_sspijp_ref ON passing_times.timetabled_

CREATE UNIQUE INDEX timetabled_passing_time_stop_point_unique_idx ON passing_times.timetabled_passing_time USING btree (vehicle_journey_id, scheduled_stop_point_in_journey_pattern_ref_id);

--
-- Name: idx_direction_the_opposite_of_direction; Type: INDEX; Schema: route; Owner: dbhasura
--

CREATE INDEX idx_direction_the_opposite_of_direction ON route.direction USING btree (the_opposite_of_direction);

--
-- Name: service_calendar_day_type_label_idx; Type: INDEX; Schema: service_calendar; Owner: dbhasura
--
Expand Down Expand Up @@ -1845,6 +1896,18 @@ CREATE TABLE passing_times.timetabled_passing_time (

ALTER TABLE passing_times.timetabled_passing_time OWNER TO dbhasura;

--
-- Name: direction; Type: TABLE; Schema: route; Owner: dbhasura
--

CREATE TABLE route.direction (
direction text NOT NULL,
the_opposite_of_direction text
);


ALTER TABLE route.direction OWNER TO dbhasura;

--
-- Name: type_of_line; Type: TABLE; Schema: route; Owner: dbhasura
--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DateTime } from 'luxon';
import { JourneyPatternRef, TypeOfLine } from '../types';
import { JourneyPatternRef, RouteDirection, TypeOfLine } from '../types';

export const journeyPatternRefsByName = {
route123Outbound: {
Expand All @@ -9,7 +9,7 @@ export const journeyPatternRefsByName = {
snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'),
type_of_line: TypeOfLine.StoppingBusService,
route_label: '123',
route_direction: 'outbound',
route_direction: RouteDirection.Outbound,
route_validity_start: DateTime.fromISO('2023-06-01T00:00:00+00:00'),
route_validity_end: DateTime.fromISO('2050-01-01T00:00:00+00:00'),
},
Expand All @@ -20,7 +20,7 @@ export const journeyPatternRefsByName = {
snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'),
type_of_line: TypeOfLine.StoppingBusService,
route_label: '123',
route_direction: 'inbound',
route_direction: RouteDirection.Inbound,
route_validity_start: DateTime.fromISO('2023-06-01T00:00:00+00:00'),
route_validity_end: DateTime.fromISO('2050-01-01T00:00:00+00:00'),
},
Expand All @@ -31,7 +31,7 @@ export const journeyPatternRefsByName = {
snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'),
type_of_line: TypeOfLine.StoppingBusService,
route_label: '234',
route_direction: 'outbound',
route_direction: RouteDirection.Outbound,
route_validity_start: DateTime.fromISO('2023-06-01T00:00:00+00:00'),
route_validity_end: DateTime.fromISO('2050-01-01T00:00:00+00:00'),
},
Expand Down Expand Up @@ -99,7 +99,7 @@ export const defaultJourneyPatternRefsByName = {
snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'),
type_of_line: TypeOfLine.StoppingBusService,
route_label: '123',
route_direction: 'outbound',
route_direction: RouteDirection.Outbound,
route_validity_start: DateTime.fromISO('2023-06-01T00:00:00+00:00'),
route_validity_end: DateTime.fromISO('2050-01-01T00:00:00+00:00'),

Expand Down Expand Up @@ -128,7 +128,7 @@ export const defaultJourneyPatternRefsByName = {
snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'),
type_of_line: TypeOfLine.StoppingBusService,
route_label: '123',
route_direction: 'inbound',
route_direction: RouteDirection.Inbound,
route_validity_start: DateTime.fromISO('2023-06-01T00:00:00+00:00'),
route_validity_end: DateTime.fromISO('2050-01-01T00:00:00+00:00'),

Expand Down Expand Up @@ -158,7 +158,7 @@ export const defaultJourneyPatternRefsByName = {
snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'),
type_of_line: TypeOfLine.StoppingBusService,
route_label: '234',
route_direction: 'outbound',
route_direction: RouteDirection.Outbound,
route_validity_start: DateTime.fromISO('2023-06-01T00:00:00+00:00'),
route_validity_end: DateTime.fromISO('2050-01-01T00:00:00+00:00'),

Expand Down
13 changes: 12 additions & 1 deletion test/hasura/generic/timetablesdb/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ export enum TypeOfLine {
FerryService = 'ferry_service',
}

export enum RouteDirection {
Inbound = 'inbound',
Outbound = 'outbound',
Clockwise = 'clockwise',
Anticlockwise = 'anticlockwise',
Northbound = 'northbound',
Southbound = 'southbound',
Eastbound = 'eastbound',
Westbound = 'westbound',
}

export type VehicleScheduleFrame = {
vehicle_schedule_frame_id: UUID;
label: string;
Expand Down Expand Up @@ -128,7 +139,7 @@ export type JourneyPatternRef = {
journey_pattern_id: UUID;
type_of_line: TypeOfLine;
route_label: string;
route_direction: string;
route_direction: RouteDirection;
route_validity_start: DateTime | null;
route_validity_end: DateTime | null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { randomUUID } from 'crypto';
import {
JourneyPatternRef,
RouteDirection,
TypeOfLine,
} from 'generic/timetablesdb/datasets/types';
import { omit } from 'lodash';
Expand All @@ -25,7 +26,7 @@ export const processJourneyPatternRef = (
snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'),
type_of_line: TypeOfLine.StoppingBusService,
route_label: '234',
route_direction: 'outbound',
route_direction: RouteDirection.Outbound,
route_validity_start: DateTime.fromISO('2023-06-01T00:00:00+00:00'),
route_validity_end: DateTime.fromISO('2051-01-01T00:00:00+00:00'),
...result,
Expand Down

0 comments on commit 347e713

Please sign in to comment.