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(); + } +}