diff --git a/src/CoreBundle/Entity/Page.php b/src/CoreBundle/Entity/Page.php index 8883211f4b..df770d1fcc 100644 --- a/src/CoreBundle/Entity/Page.php +++ b/src/CoreBundle/Entity/Page.php @@ -114,7 +114,7 @@ class Page /** * @ORM\ManyToOne(targetEntity="AccessUrl", cascade={"persist"}) - * @ORM\JoinColumn(name="access_url_id", referencedColumnName="id") + * @ORM\JoinColumn(name="access_url_id", referencedColumnName="id", onDelete="CASCADE") */ #[Assert\NotNull] #[Groups(['page:read', 'page:write'])] diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20211026140820.php b/src/CoreBundle/Migrations/Schema/V200/Version20211026140820.php new file mode 100644 index 0000000000..4bd8bb01e5 --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20211026140820.php @@ -0,0 +1,33 @@ +hasTable('page')) { + $this->addSql("CREATE TABLE page (id BIGINT AUTO_INCREMENT NOT NULL, access_url_id INT DEFAULT NULL, creator_id INT DEFAULT NULL, category_id BIGINT DEFAULT NULL, title VARCHAR(255) NOT NULL, content LONGTEXT NOT NULL, slug VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, position INT NOT NULL, locale VARCHAR(10) NOT NULL, created_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', INDEX IDX_140AB62073444FD5 (access_url_id), INDEX IDX_140AB62061220EA6 (creator_id), INDEX IDX_140AB62012469DE2 (category_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;"); + $this->addSql("CREATE TABLE page_category (id BIGINT AUTO_INCREMENT NOT NULL, creator_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, content LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', INDEX IDX_86D31EE161220EA6 (creator_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;"); + + $this->addSql('ALTER TABLE page ADD CONSTRAINT FK_140AB62073444FD5 FOREIGN KEY (access_url_id) REFERENCES access_url (id) ON DELETE CASCADE;'); + $this->addSql('ALTER TABLE page ADD CONSTRAINT FK_140AB62061220EA6 FOREIGN KEY (creator_id) REFERENCES user (id) ON DELETE CASCADE;'); + $this->addSql('ALTER TABLE page ADD CONSTRAINT FK_140AB62012469DE2 FOREIGN KEY (category_id) REFERENCES page_category (id) ON DELETE SET NULL;'); + $this->addSql('ALTER TABLE page_category ADD CONSTRAINT FK_86D31EE161220EA6 FOREIGN KEY (creator_id) REFERENCES user (id) ON DELETE CASCADE;'); + } + } + + public function down(Schema $schema): void + { + } +}