From 6aa145dccfef0915a25ab543f3e8e9c8828e2fe9 Mon Sep 17 00:00:00 2001 From: NicoDucou Date: Fri, 15 Dec 2023 11:49:26 +0100 Subject: [PATCH] Migration: Social: move social_post_attachments to previous migration to avoid error of missing table -refs BT#21270 --- .../Schema/V200/Version20230720222140.php | 8 +++++++- .../Schema/V200/Version20231026221100.php | 13 ------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230720222140.php b/src/CoreBundle/Migrations/Schema/V200/Version20230720222140.php index e13491cd47..0a822f0f07 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20230720222140.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20230720222140.php @@ -17,11 +17,17 @@ final class Version20230720222140 extends AbstractMigrationChamilo { public function getDescription(): string { - return 'Rename my_files path by resource file path'; + return 'Add table social_post_attachments and rename my_files path by resource file path'; } public function up(Schema $schema): void { + if (false === $schema->hasTable('social_post_attachments')) { + $this->addSql("CREATE TABLE social_post_attachments (id INT AUTO_INCREMENT NOT NULL, social_post_id BIGINT DEFAULT NULL, resource_node_id BIGINT DEFAULT NULL, path VARCHAR(255) NOT NULL, filename LONGTEXT NOT NULL, size INT NOT NULL, sys_insert_user_id INT NOT NULL, sys_insert_datetime DATETIME NOT NULL COMMENT '(DC2Type:datetime)', sys_lastedit_user_id INT DEFAULT NULL, sys_lastedit_datetime DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)', INDEX IDX_DF2A8F34C4F2D6B1 (social_post_id), UNIQUE INDEX UNIQ_DF2A8F341BAD783F (resource_node_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;"); + $this->addSql('ALTER TABLE social_post_attachments ADD CONSTRAINT FK_DF2A8F34C4F2D6B1 FOREIGN KEY (social_post_id) REFERENCES social_post (id) ON DELETE CASCADE;'); + $this->addSql('ALTER TABLE social_post_attachments ADD CONSTRAINT FK_DF2A8F341BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'); + } + $container = $this->getContainer(); $em = $this->getEntityManager(); /** @var Connection $connection */ diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20231026221100.php b/src/CoreBundle/Migrations/Schema/V200/Version20231026221100.php index 19ffb20803..142c2ffa11 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20231026221100.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20231026221100.php @@ -11,17 +11,4 @@ use Doctrine\DBAL\Schema\Schema; class Version20231026221100 extends AbstractMigrationChamilo { - public function getDescription(): string - { - return 'Add table social_post_attachments'; - } - - public function up(Schema $schema): void - { - if (false === $schema->hasTable('social_post_attachments')) { - $this->addSql("CREATE TABLE social_post_attachments (id INT AUTO_INCREMENT NOT NULL, social_post_id BIGINT DEFAULT NULL, resource_node_id BIGINT DEFAULT NULL, path VARCHAR(255) NOT NULL, filename LONGTEXT NOT NULL, size INT NOT NULL, sys_insert_user_id INT NOT NULL, sys_insert_datetime DATETIME NOT NULL COMMENT '(DC2Type:datetime)', sys_lastedit_user_id INT DEFAULT NULL, sys_lastedit_datetime DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)', INDEX IDX_DF2A8F34C4F2D6B1 (social_post_id), UNIQUE INDEX UNIQ_DF2A8F341BAD783F (resource_node_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;"); - $this->addSql('ALTER TABLE social_post_attachments ADD CONSTRAINT FK_DF2A8F34C4F2D6B1 FOREIGN KEY (social_post_id) REFERENCES social_post (id) ON DELETE CASCADE;'); - $this->addSql('ALTER TABLE social_post_attachments ADD CONSTRAINT FK_DF2A8F341BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'); - } - } }