From 34f22d237ed571f01cf18fbc1215a5ebd013a3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 27 Jul 2021 18:29:48 +0200 Subject: [PATCH] update schema to store location on accompanying period --- .../Entity/AccompanyingPeriod.php | 17 ++++++++ .../ChillPersonBundle/Entity/Person.php | 14 +++++++ .../migrations/Version20210727152826.php | 39 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210727152826.php diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index b2de73651..41835e237 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -25,6 +25,7 @@ namespace Chill\PersonBundle\Entity; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Entity\Scope; +use Chill\MainBundle\Entity\Address; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; @@ -291,6 +292,22 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface */ private Collection $works; + /** + * @ORM\ManyToOne( + * targetEntity=Person::class, + * inversedBy="periodLocatedOn" + * ) + */ + private ?Person $personLocation = null; + + + /** + * @ORM\ManyToOne( + * targetEntity=Address::class + * ) + */ + private ?Address $addressLocation = null; + /** * AccompanyingPeriod constructor. * diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 695970bfa..cf00eb9f1 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -30,6 +30,7 @@ use Chill\MainBundle\Entity\Country; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\MaritalStatus; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\Address; @@ -379,6 +380,19 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private Collection $householdAddresses; + /** + * @ORM\OneToMany( + * targetEntity=AccompanyingPeriod::class, + * mappedBy="personLocation" + * ) + */ + private Collection $periodLocatedOn; + + /** + * Person constructor. + * + * @param \DateTime|null $opening + */ public function __construct() { $this->accompanyingPeriodParticipations = new ArrayCollection(); diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210727152826.php b/src/Bundle/ChillPersonBundle/migrations/Version20210727152826.php new file mode 100644 index 000000000..f49c819d7 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210727152826.php @@ -0,0 +1,39 @@ +addSql('ALTER TABLE chill_person_accompanying_period ADD personLocation_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD addressLocation_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A868D5213D34 FOREIGN KEY (personLocation_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A8689B07D6BF FOREIGN KEY (addressLocation_id) REFERENCES chill_main_address (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_E260A868D5213D34 ON chill_person_accompanying_period (personLocation_id)'); + $this->addSql('CREATE INDEX IDX_E260A8689B07D6BF ON chill_person_accompanying_period (addressLocation_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A868D5213D34'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A8689B07D6BF'); + $this->addSql('DROP INDEX IDX_E260A868D5213D34'); + $this->addSql('DROP INDEX IDX_E260A8689B07D6BF'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP personLocation_id'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP addressLocation_id'); + } +}