migrations/Version20221202143634.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20221202143634 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->connection->update('news', [
  18.             'is_published' => true,
  19.             'published_at' => (new \DateTime())->format('Y-m-d H:i:s'),
  20.             'published_by_id' => 1,
  21.         ], ['1' => 1]);
  22.         // this up() migration is auto-generated, please modify it to your needs
  23.         $this->addSql('CREATE TABLE issue (id SERIAL NOT NULL, issue_topic_id INT NOT NULL, sport_object_id INT DEFAULT NULL, organization_id INT DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, body VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))');
  24.         $this->addSql('CREATE INDEX IDX_12AD233EC8FD0A96 ON issue (issue_topic_id)');
  25.         $this->addSql('CREATE INDEX IDX_12AD233E8AFAE46 ON issue (sport_object_id)');
  26.         $this->addSql('CREATE INDEX IDX_12AD233E32C8A3DE ON issue (organization_id)');
  27.         $this->addSql('COMMENT ON TABLE issue IS \'Жалобы пользователей\'');
  28.         $this->addSql('COMMENT ON COLUMN issue.created_at IS \'Дата создания\'');
  29.         $this->addSql('COMMENT ON COLUMN issue.body IS \'Текст жалобы\'');
  30.         $this->addSql('CREATE TABLE issue_topic (id SERIAL NOT NULL, created_by_id INT NOT NULL, removed_by_id INT DEFAULT NULL, published_by_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, removed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, is_published BOOLEAN NOT NULL, published_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  31.         $this->addSql('CREATE INDEX IDX_FCAB748B03A8386 ON issue_topic (created_by_id)');
  32.         $this->addSql('CREATE INDEX IDX_FCAB7482BD701DA ON issue_topic (removed_by_id)');
  33.         $this->addSql('CREATE INDEX IDX_FCAB7485B075477 ON issue_topic (published_by_id)');
  34.         $this->addSql('COMMENT ON TABLE issue_topic IS \'Типы жалоб пользователей\'');
  35.         $this->addSql('COMMENT ON COLUMN issue_topic.name IS \'Наименование\'');
  36.         $this->addSql('COMMENT ON COLUMN issue_topic.removed_at IS \'Когда удалено\'');
  37.         $this->addSql('COMMENT ON COLUMN issue_topic.is_published IS \'Признак публикации\'');
  38.         $this->addSql('COMMENT ON COLUMN issue_topic.published_at IS \'Дата публикации\'');
  39.         $this->addSql('ALTER TABLE issue ADD CONSTRAINT FK_12AD233EC8FD0A96 FOREIGN KEY (issue_topic_id) REFERENCES issue_topic (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  40.         $this->addSql('ALTER TABLE issue ADD CONSTRAINT FK_12AD233E8AFAE46 FOREIGN KEY (sport_object_id) REFERENCES sport_object (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  41.         $this->addSql('ALTER TABLE issue ADD CONSTRAINT FK_12AD233E32C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  42.         $this->addSql('ALTER TABLE issue_topic ADD CONSTRAINT FK_FCAB748B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  43.         $this->addSql('ALTER TABLE issue_topic ADD CONSTRAINT FK_FCAB7482BD701DA FOREIGN KEY (removed_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  44.         $this->addSql('ALTER TABLE issue_topic ADD CONSTRAINT FK_FCAB7485B075477 FOREIGN KEY (published_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  45.         $this->addSql('ALTER TABLE news ALTER is_published SET NOT NULL');
  46.     }
  47.     public function postUp(Schema $schema): void
  48.     {
  49.         $arr = [
  50.             'created_by_id' => 1,
  51.             'is_published' => true,
  52.             'published_at' => (new \DateTime())->format('Y-m-d H:i:s'),
  53.             'published_by_id' => 1,
  54.         ];
  55.         $topics = ['Не актуальная информация''Невозможно дозвониться''Другая причина'];
  56.         foreach ($topics as $topic) {
  57.             $resArr array_merge($arr, ['name' => $topic]);
  58.             $this->connection->insert('issue_topic'$resArr);
  59.         }
  60.     }
  61.     public function down(Schema $schema): void
  62.     {
  63.         // this down() migration is auto-generated, please modify it to your needs
  64.         $this->addSql('ALTER TABLE issue DROP CONSTRAINT FK_12AD233EC8FD0A96');
  65.         $this->addSql('ALTER TABLE issue DROP CONSTRAINT FK_12AD233E8AFAE46');
  66.         $this->addSql('ALTER TABLE issue DROP CONSTRAINT FK_12AD233E32C8A3DE');
  67.         $this->addSql('ALTER TABLE issue_topic DROP CONSTRAINT FK_FCAB748B03A8386');
  68.         $this->addSql('ALTER TABLE issue_topic DROP CONSTRAINT FK_FCAB7482BD701DA');
  69.         $this->addSql('ALTER TABLE issue_topic DROP CONSTRAINT FK_FCAB7485B075477');
  70.         $this->addSql('DROP TABLE issue');
  71.         $this->addSql('DROP TABLE issue_topic');
  72.         $this->addSql('ALTER TABLE news ALTER is_published DROP NOT NULL');
  73.     }
  74. }