migrations/Version20221216074924.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 Version20221216074924 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('CREATE TABLE organization_type (id SERIAL NOT NULL, created_by_id INT NOT NULL, removed_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, PRIMARY KEY(id))');
  19.         $this->addSql('CREATE INDEX IDX_B5D769B4B03A8386 ON organization_type (created_by_id)');
  20.         $this->addSql('CREATE INDEX IDX_B5D769B42BD701DA ON organization_type (removed_by_id)');
  21.         $this->addSql('COMMENT ON TABLE organization_type IS \'Типы спортивных организаций\'');
  22.         $this->addSql('COMMENT ON COLUMN organization_type.name IS \'Наименование\'');
  23.         $this->addSql('COMMENT ON COLUMN organization_type.removed_at IS \'Когда удалено\'');
  24.         $this->addSql('ALTER TABLE organization_type ADD CONSTRAINT FK_B5D769B4B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  25.         $this->addSql('ALTER TABLE organization_type ADD CONSTRAINT FK_B5D769B42BD701DA FOREIGN KEY (removed_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  26.         $this->addSql('ALTER TABLE organization ADD organization_type_id INT NULL');
  27.         $this->addSql('ALTER TABLE organization ADD CONSTRAINT FK_C1EE637C89E04D0 FOREIGN KEY (organization_type_id) REFERENCES organization_type (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  28.         $this->addSql('CREATE INDEX IDX_C1EE637C89E04D0 ON organization (organization_type_id)');
  29.     }
  30.     public function postUp(Schema $schema): void
  31.     {
  32.         $organizationTypes = ['Спортшколы''Федерации''Профессиональные образовательные органы''Центры спортивной подготовки',];
  33.         foreach ($organizationTypes as $organizationType) {
  34.             $this->connection->insert('organization_type', [
  35.                 'name' => $organizationType,
  36.                 'created_by_id' => 1,
  37.             ]);
  38.             $id $this->connection->lastInsertId();
  39.         }
  40.         $this->connection->executeQuery("UPDATE organization SET organization_type_id =" $id);
  41.         $this->connection->executeQuery('ALTER TABLE organization ALTER organization_type_id SET NOT NULL');
  42.     }
  43.     public function down(Schema $schema): void
  44.     {
  45.         // this down() migration is auto-generated, please modify it to your needs
  46.         $this->addSql('ALTER TABLE organization DROP CONSTRAINT FK_C1EE637C89E04D0');
  47.         $this->addSql('ALTER TABLE organization_type DROP CONSTRAINT FK_B5D769B4B03A8386');
  48.         $this->addSql('ALTER TABLE organization_type DROP CONSTRAINT FK_B5D769B42BD701DA');
  49.         $this->addSql('DROP TABLE organization_type');
  50.         $this->addSql('DROP INDEX IDX_C1EE637C89E04D0');
  51.         $this->addSql('ALTER TABLE organization DROP organization_type_id');
  52.     }
  53. }