diff --git a/metadata/hsl/databases/timetables/tables/substitute_operating_period.yaml b/metadata/hsl/databases/timetables/tables/substitute_operating_period.yaml new file mode 100644 index 00000000..52ad3466 --- /dev/null +++ b/metadata/hsl/databases/timetables/tables/substitute_operating_period.yaml @@ -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 diff --git a/metadata/hsl/databases/timetables/tables/tables.yaml b/metadata/hsl/databases/timetables/tables/tables.yaml index b1151798..12f14b6f 100644 --- a/metadata/hsl/databases/timetables/tables/tables.yaml +++ b/metadata/hsl/databases/timetables/tables/tables.yaml @@ -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" diff --git a/migrations/hsl/timetables/1683624912748_create_substitute_operating_period/down.sql b/migrations/hsl/timetables/1683624912748_create_substitute_operating_period/down.sql new file mode 100644 index 00000000..fce867f1 --- /dev/null +++ b/migrations/hsl/timetables/1683624912748_create_substitute_operating_period/down.sql @@ -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; diff --git a/migrations/hsl/timetables/1683624912748_create_substitute_operating_period/up.sql b/migrations/hsl/timetables/1683624912748_create_substitute_operating_period/up.sql new file mode 100644 index 00000000..3756c88e --- /dev/null +++ b/migrations/hsl/timetables/1683624912748_create_substitute_operating_period/up.sql @@ -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'; diff --git a/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/expressBusServiceSaturday20230520.ts b/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/expressBusServiceSaturday20230520.ts index f1517470..576f546a 100644 --- a/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/expressBusServiceSaturday20230520.ts +++ b/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/expressBusServiceSaturday20230520.ts @@ -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[] = [ + { + name: 'service_calendar.substitute_operating_period', + data: [expressBusServiceSaturday20230520SubstituteOperatingPeriod], + }, { name: 'service_calendar.substitute_operating_day_by_line_type', data: [expressBusServiceSaturday20230520SubstituteOperatingDayByLineType], diff --git a/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/stoppingBusServiceSaturday20230520.ts b/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/stoppingBusServiceSaturday20230520.ts index 93d3f93c..d2dc9f2e 100644 --- a/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/stoppingBusServiceSaturday20230520.ts +++ b/test/hasura/hsl/timetablesdb/datasets/additional-sets/substitute-operating-days-by-line-types/stoppingBusServiceSaturday20230520.ts @@ -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[] = [ { @@ -18,4 +25,8 @@ export const stoppingBusServiceSaturday20230520Dataset: TableData tableSchema.name, ), diff --git a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/substitute-operating-day-by-line-types.ts b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/substitute-operating-day-by-line-types.ts index aa597016..c460c3c5 100644 --- a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/substitute-operating-day-by-line-types.ts +++ b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/substitute-operating-day-by-line-types.ts @@ -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', }, }; diff --git a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/substitute_operating_period.ts b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/substitute_operating_period.ts new file mode 100644 index 00000000..aa4eb8dd --- /dev/null +++ b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/substitute_operating_period.ts @@ -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); diff --git a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/table-data.ts b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/table-data.ts index 0dfd854c..2e48e7db 100644 --- a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/table-data.ts +++ b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/table-data.ts @@ -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'; @@ -27,6 +28,10 @@ export const defaultHslTimetablesDbData: TableData[] = [ ], (tableSchema) => tableSchema.name, ), + { + name: 'service_calendar.substitute_operating_period', + data: substituteOperatingPeriod, + }, { name: 'service_calendar.substitute_operating_day_by_line_type', data: substituteOperatingDayByLineTypes, diff --git a/test/hasura/hsl/timetablesdb/datasets/schema.ts b/test/hasura/hsl/timetablesdb/datasets/schema.ts index 1be0182a..6ec5cb89 100644 --- a/test/hasura/hsl/timetablesdb/datasets/schema.ts +++ b/test/hasura/hsl/timetablesdb/datasets/schema.ts @@ -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]; @@ -16,4 +20,8 @@ export const hslTimetablesDbSchema: TableSchemaMap = { name: 'service_calendar.substitute_operating_day_by_line_type', props: substituteOperatingDayByLineTypeProps, }, + 'service_calendar.substitute_operating_period': { + name: 'service_calendar.substitute_operating_period', + props: SubstituteOperatingPeriodProps, + }, }; diff --git a/test/hasura/hsl/timetablesdb/datasets/types.ts b/test/hasura/hsl/timetablesdb/datasets/types.ts index 2d10752d..c3c86e1a 100644 --- a/test/hasura/hsl/timetablesdb/datasets/types.ts +++ b/test/hasura/hsl/timetablesdb/datasets/types.ts @@ -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 = { @@ -42,6 +48,7 @@ export type SubstituteOperatingDayByLineType = { timezone?: string; begin_datetime?: DateTime; end_datetime?: DateTime; + substitute_operating_period_id: UUID; }; export type TimetableVersion = { @@ -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; +};