diff --git a/CHANGELOG.md b/CHANGELOG.md index 35352116a..e1ee1c4f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to * [person] create an accompanying course: add client-side validation if no origin (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/210) +* [person] fix bounds for computing current person address: the new address appears immediatly * [main] fix adding multiple AddresseDeRelais (combine PickAddressType with ChillCollection) * [person]: do not suggest the current household of the person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/51) diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211119215630.php b/src/Bundle/ChillPersonBundle/migrations/Version20211119215630.php new file mode 100644 index 000000000..45d76f14c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211119215630.php @@ -0,0 +1,58 @@ +addSql("CREATE OR REPLACE VIEW view_chill_person_current_address AS + SELECT + cphm.person_id AS person_id, + cma.id AS address_id, + CASE WHEN cphm.startdate > COALESCE(cma.validfrom, '-infinity'::date) THEN cphm.startdate ELSE cma.validfrom END AS valid_from, + CASE WHEN COALESCE(cphm.enddate, 'infinity'::date) < COALESCE(cma.validto, 'infinity'::date) THEN cphm.enddate ELSE cma.validto END AS valid_to + FROM chill_person_household_members AS cphm + LEFT JOIN chill_person_household_to_addresses AS cphta ON cphta.household_id = cphm.household_id + LEFT JOIN chill_main_address AS cma ON cphta.address_id = cma.id + WHERE + cphm.sharedhousehold IS TRUE + AND + daterange(cphm.startdate, cphm.enddate, '[)') @> current_date + AND + daterange(cma.validfrom, cma.validto, '[)') @> current_date + "); + } + + public function down(Schema $schema): void + { + $this->addSql("CREATE VIEW view_chill_person_current_address AS + SELECT + cphm.person_id AS person_id, + cma.id AS address_id, + CASE WHEN cphm.startdate > COALESCE(cma.validfrom, '-infinity'::date) THEN cphm.startdate ELSE cma.validfrom END AS valid_from, + CASE WHEN COALESCE(cphm.enddate, 'infinity'::date) < COALESCE(cma.validto, 'infinity'::date) THEN cphm.enddate ELSE cma.validto END AS valid_to + FROM chill_person_household_members AS cphm + LEFT JOIN chill_person_household_to_addresses AS cphta ON cphta.household_id = cphm.household_id + LEFT JOIN chill_main_address AS cma ON cphta.address_id = cma.id + WHERE + cphm.sharedhousehold IS TRUE + AND + current_date between cphm.startdate AND coalesce(enddate, 'infinity'::date) + AND + current_date between cma.validfrom AND coalesce(validto, 'infinity'::date) + "); + + + } +}