diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210528090000.php b/src/Bundle/ChillMainBundle/migrations/Version20210528090000.php new file mode 100644 index 000000000..de3c7336a --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210528090000.php @@ -0,0 +1,29 @@ +addSql('CREATE EXTENSION IF NOT EXISTS btree_gist'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP EXTENSION btree_gist'); + } +} diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index 4e8787a96..420325d6d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -8,6 +8,9 @@ use Chill\MainBundle\Entity\Address; /** * @ORM\Entity + * @ORM\Table( + * name="chill_person_household" + * ) */ class Household { diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php index 5d16649a8..d39034e32 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php @@ -5,9 +5,14 @@ namespace Chill\PersonBundle\Entity\Household; use Doctrine\ORM\Mapping as ORM; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Household\Household; +use Chill\PersonBundle\Entity\Household\Position; + /** * @ORM\Entity + * @ORM\Table( + * name="chill_person_household_members" + * ) */ class HouseholdMembers { @@ -19,7 +24,7 @@ class HouseholdMembers private $id; /** - * @ORM\Column(type="string", length=255, nullable=true) + * @ORM\ManyToOne(targetEntity=Position::class) */ private $position; diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Position.php b/src/Bundle/ChillPersonBundle/Entity/Household/Position.php new file mode 100644 index 000000000..60e19b25a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Position.php @@ -0,0 +1,93 @@ +id; + } + + public function getLabel(): ?array + { + return $this->label; + } + + public function setLabel(array $label): self + { + $this->label = $label; + + return $this; + } + + public function getShareHouseHold(): ?bool + { + return $this->shareHouseHold; + } + + public function setShareHouseHold(bool $shareHouseHold): self + { + $this->shareHouseHold = $shareHouseHold; + + return $this; + } + + public function getAllowHolder(): ?bool + { + return $this->allowHolder; + } + + public function setAllowHolder(bool $allowHolder): self + { + $this->allowHolder = $allowHolder; + + return $this; + } + + public function getOrdering(): ?float + { + return $this->ordering; + } + + public function setOrdering(float $ordering): self + { + $this->ordering = $ordering; + + return $this; + } +} diff --git a/src/Bundle/ChillPersonBundle/Household b/src/Bundle/ChillPersonBundle/Household new file mode 100644 index 000000000..e69de29bb diff --git a/src/Bundle/ChillPersonBundle/Repository/Household/PositionRepository.php b/src/Bundle/ChillPersonBundle/Repository/Household/PositionRepository.php new file mode 100644 index 000000000..0ca9ef10e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/Household/PositionRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('p') + ->andWhere('p.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('p.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Position + { + return $this->createQueryBuilder('p') + ->andWhere('p.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210528092625.php b/src/Bundle/ChillPersonBundle/migrations/Version20210528092625.php new file mode 100644 index 000000000..5d1909424 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210528092625.php @@ -0,0 +1,62 @@ +addSql('ALTER TABLE householdmembers DROP CONSTRAINT fk_4d1fb288e79ff843'); + $this->addSql('ALTER TABLE householdmembers DROP CONSTRAINT fk_4d1fb288217bbb47'); + + // rename tables + $this->addSql('ALTER TABLE householdmembers RENAME TO chill_person_household_members'); + $this->addSql('ALTER TABLE household RENAME TO chill_person_household'); + + // rename sequences + $this->addSql('ALTER SEQUENCE household_id_seq RENAME TO chill_person_household_id_seq'); + $this->addSql('ALTER SEQUENCE householdmembers_id_seq RENAME TO chill_person_household_members_id_seq'); + + // recreate constraints + $this->addSql('ALTER TABLE chill_person_household_members ADD CONSTRAINT FK_EEF5DED7217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_household_members ADD CONSTRAINT FK_EEF5DED7E79FF843 FOREIGN KEY (household_id) REFERENCES chill_person_household (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + + // create constraint 'householdmembers not overlaps' + $this->addSql('ALTER TABLE chill_person_household_members ADD CHECK (startdate < enddate)'); + $this->addSql('ALTER TABLE chill_person_household_members ADD CONSTRAINT '. + "household_members_not_overlaps EXCLUDE USING GIST( + -- extension btree_gist required to include comparaison with integer + person_id WITH =, + daterange(startdate, enddate) WITH && + ) WHERE (sharedhousehold IS TRUE)"); + + // rename constraints + $this->addSql('ALTER TABLE public.chill_person_household_to_addresses DROP CONSTRAINT fk_7109483e79ff843'); + $this->addSql('ALTER TABLE chill_person_household_to_addresses ADD CONSTRAINT FK_C28AF063E79FF843 FOREIGN KEY (household_id) REFERENCES chill_person_household (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + + // rename indexes + $this->addSql('ALTER INDEX idx_7109483e79ff843 RENAME TO IDX_C28AF063E79FF843'); + $this->addSql('ALTER INDEX idx_7109483f5b7af75 RENAME TO IDX_C28AF063F5B7AF75'); + $this->addSql('ALTER INDEX idx_4d1fb288e79ff843 RENAME TO IDX_EEF5DED7E79FF843'); + $this->addSql('ALTER INDEX idx_4d1fb288217bbb47 RENAME TO IDX_EEF5DED7217BBB47'); + } + + public function down(Schema $schema): void + { + $this->throwIrreversibleMigrationException("the down method is not implemented"); + } +} diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210528111624.php b/src/Bundle/ChillPersonBundle/migrations/Version20210528111624.php new file mode 100644 index 000000000..2228d42c3 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210528111624.php @@ -0,0 +1,39 @@ +addSql('CREATE SEQUENCE chill_person_household_position_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_person_household_position (id INT NOT NULL, label JSON NOT NULL, shareHouseHold BOOLEAN NOT NULL, allowHolder BOOLEAN NOT NULL, ordering DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))'); + + $this->addSql('ALTER TABLE chill_person_household_members ADD position_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_household_members DROP "position"'); + $this->addSql('ALTER TABLE chill_person_household_members ADD CONSTRAINT FK_EEF5DED7DD842E46 FOREIGN KEY (position_id) REFERENCES chill_person_household_position (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_EEF5DED7DD842E46 ON chill_person_household_members (position_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_household_members DROP CONSTRAINT FK_EEF5DED7DD842E46'); + $this->addSql('DROP SEQUENCE chill_person_household_position_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_person_household_position'); + $this->addSql('ALTER TABLE chill_person_household_members ADD "position" VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_household_members DROP position_id'); + } +}