diff --git a/src/migrations/20260109_023000_add_locations_hours_structured.ts b/src/migrations/20260109_023000_add_locations_hours_structured.ts new file mode 100644 index 0000000..6021b54 --- /dev/null +++ b/src/migrations/20260109_023000_add_locations_hours_structured.ts @@ -0,0 +1,35 @@ +import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres' + +/** + * Migration: Add missing locations_hours_structured table + * + * The Locations collection has an array field for structured opening hours + * that requires this table to store the nested data. + */ +export async function up({ db, payload, req }: MigrateUpArgs): Promise { + await db.execute(sql` + CREATE TABLE IF NOT EXISTS "locations_hours_structured" ( + "id" serial PRIMARY KEY NOT NULL, + "_order" integer NOT NULL, + "_parent_id" integer NOT NULL REFERENCES locations(id) ON DELETE CASCADE, + "day" varchar, + "closed" boolean DEFAULT false, + "open" varchar, + "close" varchar, + "break_has_break" boolean DEFAULT false, + "break_start" varchar, + "break_end" varchar + ); + + CREATE INDEX IF NOT EXISTS "locations_hours_structured_order_idx" + ON "locations_hours_structured" USING btree ("_order"); + CREATE INDEX IF NOT EXISTS "locations_hours_structured_parent_idx" + ON "locations_hours_structured" USING btree ("_parent_id"); + `) +} + +export async function down({ db, payload, req }: MigrateDownArgs): Promise { + await db.execute(sql` + DROP TABLE IF EXISTS "locations_hours_structured"; + `) +} diff --git a/src/migrations/index.ts b/src/migrations/index.ts index 7c9f91c..287980f 100644 --- a/src/migrations/index.ts +++ b/src/migrations/index.ts @@ -26,6 +26,7 @@ import * as migration_20260108_230500_add_pages_blocks_missing from './20260108_ import * as migration_20260108_231200_add_video_embed_block_tables from './20260108_231200_add_video_embed_block_tables'; import * as migration_20260108_231400_add_pages_rels_missing_columns from './20260108_231400_add_pages_rels_missing_columns'; import * as migration_20260109_020000_add_blogwoman_collections from './20260109_020000_add_blogwoman_collections'; +import * as migration_20260109_023000_add_locations_hours_structured from './20260109_023000_add_locations_hours_structured'; export const migrations = [ { @@ -168,4 +169,9 @@ export const migrations = [ down: migration_20260109_020000_add_blogwoman_collections.down, name: '20260109_020000_add_blogwoman_collections' }, + { + up: migration_20260109_023000_add_locations_hours_structured.up, + down: migration_20260109_023000_add_locations_hours_structured.down, + name: '20260109_023000_add_locations_hours_structured' + }, ];