From 49f99a6b9c47550d9d241428aecf3a445b06534f Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Fri, 25 Jul 2025 15:31:39 -0400 Subject: [PATCH] feat(module): setup for pay-period view with navigation and search options. --- .../migration.sql | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 prisma/migrations/20250724191659_create_pay_period_view/migration.sql diff --git a/prisma/migrations/20250724191659_create_pay_period_view/migration.sql b/prisma/migrations/20250724191659_create_pay_period_view/migration.sql new file mode 100644 index 0000000..c58f9c8 --- /dev/null +++ b/prisma/migrations/20250724191659_create_pay_period_view/migration.sql @@ -0,0 +1,47 @@ +-- This is an empty migration. +-- Date d'ancrage fix. Période 1 = 2023-12-17 => 2023-12-30 +WITH anchor AS ( + SELECT '2023-12-17'::date AS anchor_date +), + + +--definition des bornes d'archivage et de visionnement futur ( 6 mois avant la periode actuelle et 1 mois apres la periode actuelle) +With bounds As ( + SELECT + (now()::date - INTERVAL ' 6 months')::date AS start_bound, + (now()::date - INTERVAL ' 1 month')::date AS end_bound, + anchor.anchor_date + FROM anchor +), + +--determination des dates d'une periode +series AS ( + SELECT + generate_series( + bounds.start_bound, + bounds.end_bound, + '14 days' + ) AS period_start + bounds.anchor_date + FROM bounds +) + +--creation de la vue +CREATE OR REPACE VIEW "pay_period" AS +SELECT + + ((row_number() OVER (ORDER BY period_start) - 1) % 26) + 1 + AS period_number, + + period_start AS start_date, --date de début de la periode + period_start + INTERVAL '13 days' AS end_date, -- date de fin de la periode + + EXTRACT(YEAR FROM period_start)::int AS year, + + --label pour affichage + || ' → ' + || to_char(period_start + INTERVAL '13 days', 'YYYY-MM-DD') + AS label + +FROM series; +OERDER BY period_start; \ No newline at end of file