diff --git a/.changes/unreleased/Feature-20230627-151615.yaml b/.changes/unreleased/Feature-20230627-151615.yaml new file mode 100644 index 000000000..499e874dc --- /dev/null +++ b/.changes/unreleased/Feature-20230627-151615.yaml @@ -0,0 +1,28 @@ +kind: Feature +body: "Force accompanying period user history to be unique for the same period and + stardate/enddate [:warning: may encounter migration issue]" +time: 2023-06-27T15:16:15.775571488+02:00 +custom: + Issue: "" + Long: "If some issue is encountered during migration, use this SQL to find the line which are in conflict, examine the problem and delete some of the concerning line + + ```sql + + -- to see the line which are in conflict with another one + + SELECT o.* + + FROM chill_person_accompanying_period_user_history o + + JOIN chill_person_accompanying_period_user_history c ON o.id < c.id AND o.accompanyingperiod_id = c.accompanyingperiod_id + + WHERE tsrange(o.startdate, o.enddate, '[)') && tsrange(c.startdate, c.enddate, '[)') + + ORDER BY accompanyingperiod_id; + + -- to examine line in conflict for a given accompanyingperiod_id (given by the previous query) + + SELECT * FROM chill_person_accompanying_period_user_history WHERE accompanyingperiod_id = IIIIDDDD order by startdate, enddate; + + ``` + " diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20230627130331.php b/src/Bundle/ChillPersonBundle/migrations/Version20230627130331.php new file mode 100644 index 000000000..63f160997 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20230627130331.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE chill_person_accompanying_period_user_history + ADD CONSTRAINT acc_period_user_history_not_overlaps + EXCLUDE USING GIST (accompanyingperiod_id with =, tsrange(startdate, enddate) with &&) + DEFERRABLE INITIALLY DEFERRED'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_accompanying_period_user_history DROP CONSTRAINT acc_period_user_history_not_overlaps'); + } +}