From afa38e9dd5854edc5260cb0f4e0b9f682b0b4b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 14 Apr 2022 01:11:39 +0200 Subject: [PATCH] addresses: add constraint in database to avoid error later --- src/Bundle/ChillMainBundle/Entity/Address.php | 1 + .../migrations/Version20220413225830.php | 27 +++++++++++++++++++ .../migrations/Version20220413230159.php | 26 ++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20220413225830.php create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20220413230159.php diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 10679d2e0..d3eee0b2a 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -140,6 +140,7 @@ class Address /** * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode") + * @ORM\JoinColumn(nullable=false) * @Groups({"write"}) */ private ?PostalCode $postcode = null; diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220413225830.php b/src/Bundle/ChillMainBundle/migrations/Version20220413225830.php new file mode 100644 index 000000000..43ef753bb --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220413225830.php @@ -0,0 +1,27 @@ +addSql('ALTER TABLE chill_main_address ALTER COLUMN postcode_id SET NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_address ALTER COLUMN postcode_id DROP NOT NULL'); + + } +} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220413230159.php b/src/Bundle/ChillMainBundle/migrations/Version20220413230159.php new file mode 100644 index 000000000..7a2ce476b --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220413230159.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE chill_main_address ADD CONSTRAINT chill_custom_validfrom_before_validto CHECK (validfrom <= COALESCE(validto, \'infinity\'::date))'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_address DROP CONSTRAINT chill_custom_validfrom_before_validto'); + } +}