<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221216074924 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$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))');
$this->addSql('CREATE INDEX IDX_B5D769B4B03A8386 ON organization_type (created_by_id)');
$this->addSql('CREATE INDEX IDX_B5D769B42BD701DA ON organization_type (removed_by_id)');
$this->addSql('COMMENT ON TABLE organization_type IS \'Типы спортивных организаций\'');
$this->addSql('COMMENT ON COLUMN organization_type.name IS \'Наименование\'');
$this->addSql('COMMENT ON COLUMN organization_type.removed_at IS \'Когда удалено\'');
$this->addSql('ALTER TABLE organization_type ADD CONSTRAINT FK_B5D769B4B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_type ADD CONSTRAINT FK_B5D769B42BD701DA FOREIGN KEY (removed_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization ADD organization_type_id INT NULL');
$this->addSql('ALTER TABLE organization ADD CONSTRAINT FK_C1EE637C89E04D0 FOREIGN KEY (organization_type_id) REFERENCES organization_type (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_C1EE637C89E04D0 ON organization (organization_type_id)');
}
public function postUp(Schema $schema): void
{
$organizationTypes = ['Спортшколы', 'Федерации', 'Профессиональные образовательные органы', 'Центры спортивной подготовки',];
foreach ($organizationTypes as $organizationType) {
$this->connection->insert('organization_type', [
'name' => $organizationType,
'created_by_id' => 1,
]);
$id = $this->connection->lastInsertId();
}
$this->connection->executeQuery("UPDATE organization SET organization_type_id =" . $id);
$this->connection->executeQuery('ALTER TABLE organization ALTER organization_type_id SET NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE organization DROP CONSTRAINT FK_C1EE637C89E04D0');
$this->addSql('ALTER TABLE organization_type DROP CONSTRAINT FK_B5D769B4B03A8386');
$this->addSql('ALTER TABLE organization_type DROP CONSTRAINT FK_B5D769B42BD701DA');
$this->addSql('DROP TABLE organization_type');
$this->addSql('DROP INDEX IDX_C1EE637C89E04D0');
$this->addSql('ALTER TABLE organization DROP organization_type_id');
}
}