<?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 Version20221111093815 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 (id SERIAL NOT NULL, file_id INT DEFAULT NULL, created_by_id INT NOT NULL, name VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, address VARCHAR(255) DEFAULT NULL, organization_info TEXT DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_C1EE637C93CB796C ON organization (file_id)');
$this->addSql('CREATE INDEX IDX_C1EE637CB03A8386 ON organization (created_by_id)');
$this->addSql('COMMENT ON TABLE organization IS \'Спортивные организации\'');
$this->addSql('COMMENT ON COLUMN organization.name IS \'Наименование\'');
$this->addSql('COMMENT ON COLUMN organization.description IS \'Описание\'');
$this->addSql('COMMENT ON COLUMN organization.address IS \'Адрес\'');
$this->addSql('COMMENT ON COLUMN organization.organization_info IS \'Информация о юр.лице\'');
$this->addSql('CREATE TABLE organization_image (organization_id INT NOT NULL, file_id INT NOT NULL, PRIMARY KEY(organization_id, file_id))');
$this->addSql('CREATE INDEX IDX_4BBAE29832C8A3DE ON organization_image (organization_id)');
$this->addSql('CREATE INDEX IDX_4BBAE29893CB796C ON organization_image (file_id)');
$this->addSql('CREATE TABLE organization_doc (organization_id INT NOT NULL, file_id INT NOT NULL, PRIMARY KEY(organization_id, file_id))');
$this->addSql('CREATE INDEX IDX_8CCCA28732C8A3DE ON organization_doc (organization_id)');
$this->addSql('CREATE INDEX IDX_8CCCA28793CB796C ON organization_doc (file_id)');
$this->addSql('CREATE TABLE organization_section (id SERIAL NOT NULL, organization_id INT DEFAULT NULL, sport_section_id INT DEFAULT NULL, sport_object_id INT DEFAULT NULL, url VARCHAR(500) DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_E0A1F2AC32C8A3DE ON organization_section (organization_id)');
$this->addSql('CREATE INDEX IDX_E0A1F2ACEB0B7C67 ON organization_section (sport_section_id)');
$this->addSql('CREATE INDEX IDX_E0A1F2AC8AFAE46 ON organization_section (sport_object_id)');
$this->addSql('CREATE UNIQUE INDEX organization_section_unique ON organization_section (organization_id, sport_section_id)');
$this->addSql('COMMENT ON TABLE organization_section IS \'Связь спортивных секций со спортивными организациями.\'');
$this->addSql('ALTER TABLE organization ADD CONSTRAINT FK_C1EE637C93CB796C FOREIGN KEY (file_id) REFERENCES file (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization ADD CONSTRAINT FK_C1EE637CB03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_image ADD CONSTRAINT FK_4BBAE29832C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_image ADD CONSTRAINT FK_4BBAE29893CB796C FOREIGN KEY (file_id) REFERENCES file (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_doc ADD CONSTRAINT FK_8CCCA28732C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_doc ADD CONSTRAINT FK_8CCCA28793CB796C FOREIGN KEY (file_id) REFERENCES file (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_section ADD CONSTRAINT FK_E0A1F2AC32C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_section ADD CONSTRAINT FK_E0A1F2ACEB0B7C67 FOREIGN KEY (sport_section_id) REFERENCES sport_section (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE organization_section ADD CONSTRAINT FK_E0A1F2AC8AFAE46 FOREIGN KEY (sport_object_id) REFERENCES sport_object (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE job ADD organization_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE job ADD organization_section_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE job ADD CONSTRAINT FK_FBD8E0F832C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE job ADD CONSTRAINT FK_FBD8E0F831787195 FOREIGN KEY (organization_section_id) REFERENCES organization_section (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_FBD8E0F832C8A3DE ON job (organization_id)');
$this->addSql('CREATE INDEX IDX_FBD8E0F831787195 ON job (organization_section_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE job DROP CONSTRAINT FK_FBD8E0F832C8A3DE');
$this->addSql('ALTER TABLE job DROP CONSTRAINT FK_FBD8E0F831787195');
$this->addSql('ALTER TABLE organization DROP CONSTRAINT FK_C1EE637C93CB796C');
$this->addSql('ALTER TABLE organization DROP CONSTRAINT FK_C1EE637CB03A8386');
$this->addSql('ALTER TABLE organization_image DROP CONSTRAINT FK_4BBAE29832C8A3DE');
$this->addSql('ALTER TABLE organization_image DROP CONSTRAINT FK_4BBAE29893CB796C');
$this->addSql('ALTER TABLE organization_doc DROP CONSTRAINT FK_8CCCA28732C8A3DE');
$this->addSql('ALTER TABLE organization_doc DROP CONSTRAINT FK_8CCCA28793CB796C');
$this->addSql('ALTER TABLE organization_section DROP CONSTRAINT FK_E0A1F2AC32C8A3DE');
$this->addSql('ALTER TABLE organization_section DROP CONSTRAINT FK_E0A1F2ACEB0B7C67');
$this->addSql('ALTER TABLE organization_section DROP CONSTRAINT FK_E0A1F2AC8AFAE46');
$this->addSql('DROP TABLE organization');
$this->addSql('DROP TABLE organization_image');
$this->addSql('DROP TABLE organization_doc');
$this->addSql('DROP TABLE organization_section');
$this->addSql('DROP INDEX IDX_FBD8E0F832C8A3DE');
$this->addSql('DROP INDEX IDX_FBD8E0F831787195');
$this->addSql('ALTER TABLE job DROP organization_id');
$this->addSql('ALTER TABLE job DROP organization_section_id');
}
}