From f7184ca7bbb3f8b12f325aefbafee945a110f12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 7 Dec 2023 23:22:48 +0100 Subject: [PATCH] Fix export for people created before 'createdAt' column introduction This commit introduces a migration to fix the export for individuals who were created before the introduction of the 'createdAt' column. The 'startdate' column is now updated to match the individual's first activity date. This migration is irreversible. It's been added as a response to Issue #228 --- .../unreleased/Fixed-20231207-232129.yaml | 6 ++ .../migrations/Version20231207221700.php | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .changes/unreleased/Fixed-20231207-232129.yaml create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20231207221700.php diff --git a/.changes/unreleased/Fixed-20231207-232129.yaml b/.changes/unreleased/Fixed-20231207-232129.yaml new file mode 100644 index 000000000..12a4666b4 --- /dev/null +++ b/.changes/unreleased/Fixed-20231207-232129.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Fix export of activity for people created before the introduction of the createdAt + column on person (during v1) +time: 2023-12-07T23:21:29.976822313+01:00 +custom: + Issue: "228" diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20231207221700.php b/src/Bundle/ChillPersonBundle/migrations/Version20231207221700.php new file mode 100644 index 000000000..80435ccf1 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20231207221700.php @@ -0,0 +1,58 @@ +addSql('WITH first_history_line AS (SELECT * + FROM (SELECT id, + person_id, + startdate, + rank() OVER (PARTITION BY person_id ORDER BY startdate ASC, id ASC) AS r + FROM chill_person_person_center_history) AS sk + WHERE sk.r = 1), + first_activity AS (SELECT * + FROM (SELECT id, date, person_id, rank() OVER (PARTITION BY person_id ORDER BY date ASC, id ASC) AS r + FROM activity + WHERE person_id IS NOT NULL) sq + WHERE sq.r = 1) +UPDATE chill_person_person_center_history cppch SET startdate=first_activity.date +FROM first_history_line, first_activity +WHERE + first_history_line.id = cppch.id + AND first_activity.person_id = cppch.person_id + AND first_activity.date < first_history_line.startDate'); + } + + public function down(Schema $schema): void + { + $this->throwIrreversibleMigrationException(); + } +}