Skip to content

Commit

Permalink
Add substitute operating period
Browse files Browse the repository at this point in the history
- New table service_calendar.substitute_operating_period to group substitute_operating_days
- New view service_calendar.substitute_operating_period_with_date_range to get periods with date range and linetypes
- New function service_calendar.save_operating_periods handles saving/updating substitute_operating_days for substitute_operating_periods
  • Loading branch information
Perholehto committed Jul 12, 2023
1 parent f0391a9 commit 85d4a35
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table:
name: substitute_operating_period
schema: service_calendar
array_relationships:
- name: substitute_operating_day_by_line_types
using:
foreign_key_constraint_on:
column: substitute_operating_period_id
table:
name: substitute_operating_day_by_line_type
schema: service_calendar
1 change: 1 addition & 0 deletions metadata/hsl/databases/timetables/tables/tables.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- "!include substitute_operating_day_by_line_type.yaml"
- "!include return_value_timetable_version.yaml"
- "!include return_value_vehicle_schedule.yaml"
- "!include substitute_operating_period.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE
ONLY service_calendar.substitute_operating_day_by_line_type DROP COLUMN substitute_operating_period_id;

DROP TABLE service_calendar.substitute_operating_period;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE service_calendar.substitute_operating_period (
substitute_operating_period_id uuid DEFAULT gen_random_uuid(),
period_name text UNIQUE NOT NULL,
is_preset boolean NOT NULL DEFAULT FALSE
);

ALTER TABLE ONLY service_calendar.substitute_operating_period
ADD CONSTRAINT substitute_operating_period_pkey PRIMARY KEY (substitute_operating_period_id);

COMMENT ON COLUMN service_calendar.substitute_operating_period.period_name IS 'Substitute operating period''s name';
COMMENT ON COLUMN service_calendar.substitute_operating_period.is_preset IS 'Flag indicating whether operating period is preset or not. Preset operating periods have restrictions on the UI';

ALTER TABLE ONLY service_calendar.substitute_operating_day_by_line_type
ADD COLUMN substitute_operating_period_id uuid NOT NULL;

ALTER TABLE ONLY service_calendar.substitute_operating_day_by_line_type
ADD CONSTRAINT substitute_operating_day_by_line_type_substitute_operating_period_fkey FOREIGN KEY (substitute_operating_period_id) REFERENCES service_calendar.substitute_operating_period(substitute_operating_period_id) ON DELETE CASCADE;

CREATE INDEX substitute_operating_day_by_line_type_substitute_operating_period
ON service_calendar.substitute_operating_day_by_line_type USING btree (substitute_operating_period_id);

COMMENT ON COLUMN service_calendar.substitute_operating_day_by_line_type.substitute_operating_period_id IS 'The id of the substitute operating period';
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ export const expressBusServiceSaturday20230520SubstituteOperatingDayByLineType =
'0967a31a-8304-4440-9a8e-18bb67b281a8',
type_of_line: TypeOfLine.ExpressBusService,
superseded_date: DateTime.fromISO('2023-05-20'),
substitute_operating_period_id: '0967a31a-8304-4440-9a8e-18bb67b28111',
};

export const expressBusServiceSaturday20230520SubstituteOperatingPeriod = {
substitute_operating_period_id: '0967a31a-8304-4440-9a8e-18bb67b28111',
is_preset: false,
period_name: 'Korvausjakso',
};

export const expressBusServiceSaturday20230520Dataset: TableData<HslTimetablesDbTables>[] =
[
{
name: 'service_calendar.substitute_operating_period',
data: [expressBusServiceSaturday20230520SubstituteOperatingPeriod],
},
{
name: 'service_calendar.substitute_operating_day_by_line_type',
data: [expressBusServiceSaturday20230520SubstituteOperatingDayByLineType],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ export const stoppingBusServiceSaturday20230520SubstituteOperatingDayByLineType
'88fbc283-9552-45d2-9365-60272f1e44f6',
type_of_line: TypeOfLine.StoppingBusService,
superseded_date: DateTime.fromISO('2023-05-20'),
substitute_operating_period_id: '88fbc283-9552-45d2-9365-60272f1e4423',
};

export const stoppingBusServiceSaturday20230520SubstituteOperatingPeriod = {
substitute_operating_period_id: '88fbc283-9552-45d2-9365-60272f1e4423',
is_preset: false,
period_name: 'Lauantain korvausjakso',
};

export const stoppingBusServiceSaturday20230520Dataset: TableData<HslTimetablesDbTables>[] =
[
{
Expand All @@ -18,4 +25,8 @@ export const stoppingBusServiceSaturday20230520Dataset: TableData<HslTimetablesD
stoppingBusServiceSaturday20230520SubstituteOperatingDayByLineType,
],
},
{
name: 'service_calendar.substitute_operating_period',
data: [stoppingBusServiceSaturday20230520SubstituteOperatingPeriod],
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const getDbDataWithAdditionalDatasets = ({
datasets,
'service_calendar.substitute_operating_day_by_line_type',
),
getCombinedData(
datasets,
'service_calendar.substitute_operating_period',
),
],
(tableSchema) => tableSchema.name,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const substituteOperatingDayByLineTypesByName = {
type_of_line: TypeOfLine.StoppingBusService,
superseded_date: DateTime.fromISO('2023-04-01'),
substitute_day_of_week: DayOfWeek.Friday,
substitute_operating_period_id: '0967a31a-8304-4440-9a8e-18bb67b28166',
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SubstituteOperatingPeriod } from '../types';

export const substituteOperatingPeriodByNames = {
aprilFools: {
substitute_operating_period_id: '0967a31a-8304-4440-9a8e-18bb67b28166',
is_preset: false,
period_name: 'Default korvausjakso',
},
};
export const substituteOperatingPeriod: SubstituteOperatingPeriod[] =
Object.values(substituteOperatingPeriodByNames);
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mergeLists } from '@util/schema';
import { defaultGenericTimetablesDbData } from 'generic/timetablesdb/datasets/defaultSetup';
import { HslTimetablesDbTables } from '../schema';
import { substituteOperatingDayByLineTypes } from './substitute-operating-day-by-line-types';
import { substituteOperatingPeriod } from './substitute_operating_period';
import { hslVehicleJourneys } from './vehicle-journeys';
import { hslVehicleScheduleFrames } from './vehicle-schedule-frames';
import { hslVehicleServices } from './vehicle-services';
Expand All @@ -27,6 +28,10 @@ export const defaultHslTimetablesDbData: TableData<HslTimetablesDbTables>[] = [
],
(tableSchema) => tableSchema.name,
),
{
name: 'service_calendar.substitute_operating_period',
data: substituteOperatingPeriod,
},
{
name: 'service_calendar.substitute_operating_day_by_line_type',
data: substituteOperatingDayByLineTypes,
Expand Down
10 changes: 9 additions & 1 deletion test/hasura/hsl/timetablesdb/datasets/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import {
genericTimetablesDbSchema,
genericTimetablesDbTables,
} from 'generic/timetablesdb/datasets/schema';
import { substituteOperatingDayByLineTypeProps } from './types';
import {
SubstituteOperatingPeriodProps,
substituteOperatingDayByLineTypeProps,
} from './types';

export const hslTimetablesDbTables = [
...genericTimetablesDbTables,
'service_calendar.substitute_operating_day_by_line_type',
'service_calendar.substitute_operating_period',
] as const;
export type HslTimetablesDbTables = (typeof hslTimetablesDbTables)[number];

Expand All @@ -16,4 +20,8 @@ export const hslTimetablesDbSchema: TableSchemaMap<HslTimetablesDbTables> = {
name: 'service_calendar.substitute_operating_day_by_line_type',
props: substituteOperatingDayByLineTypeProps,
},
'service_calendar.substitute_operating_period': {
name: 'service_calendar.substitute_operating_period',
props: SubstituteOperatingPeriodProps,
},
};
13 changes: 13 additions & 0 deletions test/hasura/hsl/timetablesdb/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export const substituteOperatingDayByLineTypeProps: Property[] = [
'timezone',
'begin_datetime',
'end_datetime',
'substitute_operating_period_id',
];
export const SubstituteOperatingPeriodProps: Property[] = [
'id,',
'period_name',
'is_preset',
];

export type SubstituteOperatingDayByLineType = {
Expand All @@ -42,6 +48,7 @@ export type SubstituteOperatingDayByLineType = {
timezone?: string;
begin_datetime?: DateTime;
end_datetime?: DateTime;
substitute_operating_period_id: UUID;
};

export type TimetableVersion = {
Expand All @@ -64,3 +71,9 @@ export type VehicleSchedule = {
validity_end: DateTime;
created_at: DateTime;
};

export type SubstituteOperatingPeriod = {
substitute_operating_period_id: UUID;
period_name: string;
is_preset: boolean;
};

0 comments on commit 85d4a35

Please sign in to comment.