<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use App\Entity\SiteSection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230323145105 extends AbstractMigration
{
const siteSections = [
[
'code' => SiteSection::SS_GTO,
'name' => 'ГТО в Татарстане',
'links' => [
[
'type' => 'feedback',
'name' => 'Не нашли нужного ответа? Больше информации Вы найдете здесь',
'url' => 'https://gto.ru/feedback',
],
]
],
[
'code' => SiteSection::SS_ADAPTIVE_SPORT,
'name' => 'Адаптивный спорт',
],
[
'code' => SiteSection::SS_ABOUT,
'name' => 'О проекте',
'links' => [
[
'type' => 'feedback',
'name' => 'Не нашли нужного ответа? Больше информации Вы найдете здесь',
'url' => 'https://gto.ru/feedback',
],
]
],
];
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 site_faq (id SERIAL NOT NULL, site_section_id INT DEFAULT NULL, created_by_id INT NOT NULL, removed_by_id INT DEFAULT NULL, question VARCHAR(255) NOT NULL, answer TEXT NOT NULL, sort INT DEFAULT 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_1C6244ECF82A6CBF ON site_faq (site_section_id)');
$this->addSql('CREATE INDEX IDX_1C6244ECB03A8386 ON site_faq (created_by_id)');
$this->addSql('CREATE INDEX IDX_1C6244EC2BD701DA ON site_faq (removed_by_id)');
$this->addSql('COMMENT ON TABLE site_faq IS \'Частые вопросы сайта (внешнего)\'');
$this->addSql('COMMENT ON COLUMN site_faq.question IS \'Вопрос\'');
$this->addSql('COMMENT ON COLUMN site_faq.answer IS \'Ответ\'');
$this->addSql('COMMENT ON COLUMN site_faq.sort IS \'Сортировка\'');
$this->addSql('COMMENT ON COLUMN site_faq.removed_at IS \'Когда удалено\'');
$this->addSql('CREATE TABLE site_section (id SERIAL NOT NULL, removed_by_id INT DEFAULT NULL, code VARCHAR(50) NOT NULL, name VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, removed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_D6D7982477153098 ON site_section (code)');
$this->addSql('CREATE INDEX IDX_D6D798242BD701DA ON site_section (removed_by_id)');
$this->addSql('COMMENT ON TABLE site_section IS \'Разделы сайта (внешнего)\'');
$this->addSql('COMMENT ON COLUMN site_section.code IS \'Кодовое наименование раздела\'');
$this->addSql('COMMENT ON COLUMN site_section.name IS \'Наименование раздела\'');
$this->addSql('COMMENT ON COLUMN site_section.description IS \'Текстовое описание раздела\'');
$this->addSql('COMMENT ON COLUMN site_section.removed_at IS \'Когда удалено\'');
$this->addSql('CREATE TABLE site_section_image (site_section_id INT NOT NULL, file_id INT NOT NULL, PRIMARY KEY(site_section_id, file_id))');
$this->addSql('CREATE INDEX IDX_C90B90F82A6CBF ON site_section_image (site_section_id)');
$this->addSql('CREATE INDEX IDX_C90B9093CB796C ON site_section_image (file_id)');
$this->addSql('CREATE TABLE site_section_banner (site_section_id INT NOT NULL, banner_id INT NOT NULL, PRIMARY KEY(site_section_id, banner_id))');
$this->addSql('CREATE INDEX IDX_648393C9F82A6CBF ON site_section_banner (site_section_id)');
$this->addSql('CREATE INDEX IDX_648393C9684EC833 ON site_section_banner (banner_id)');
$this->addSql('ALTER TABLE site_faq ADD CONSTRAINT FK_1C6244ECF82A6CBF FOREIGN KEY (site_section_id) REFERENCES site_section (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE site_faq ADD CONSTRAINT FK_1C6244ECB03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE site_faq ADD CONSTRAINT FK_1C6244EC2BD701DA FOREIGN KEY (removed_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE site_section ADD CONSTRAINT FK_D6D798242BD701DA FOREIGN KEY (removed_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE site_section_image ADD CONSTRAINT FK_C90B90F82A6CBF FOREIGN KEY (site_section_id) REFERENCES site_section (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE site_section_image ADD CONSTRAINT FK_C90B9093CB796C FOREIGN KEY (file_id) REFERENCES file (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE site_section_banner ADD CONSTRAINT FK_648393C9F82A6CBF FOREIGN KEY (site_section_id) REFERENCES site_section (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE site_section_banner ADD CONSTRAINT FK_648393C9684EC833 FOREIGN KEY (banner_id) REFERENCES banner (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE links ADD site_section_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE links ADD CONSTRAINT FK_D182A118F82A6CBF FOREIGN KEY (site_section_id) REFERENCES site_section (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_D182A118F82A6CBF ON links (site_section_id)');
$id = 1;
foreach (self::siteSections as $siteSection) {
$this->addSql(sprintf('INSERT INTO site_section (code, name) VALUES (\'%s\', \'%s\')',
$siteSection['code'], $siteSection['name']
));
if (isset($siteSection['links'])) {
foreach ($siteSection['links'] as $link) {
$this->addSql(sprintf('INSERT INTO links (created_by_id, type, name, url, site_section_id) VALUES (1, \'%s\', \'%s\', \'%s\', %d)',
$link['type'], $link['name'], $link['url'], $id
));
}
}
$id++;
}
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE links DROP CONSTRAINT FK_D182A118F82A6CBF');
$this->addSql('ALTER TABLE site_faq DROP CONSTRAINT FK_1C6244ECF82A6CBF');
$this->addSql('ALTER TABLE site_faq DROP CONSTRAINT FK_1C6244ECB03A8386');
$this->addSql('ALTER TABLE site_faq DROP CONSTRAINT FK_1C6244EC2BD701DA');
$this->addSql('ALTER TABLE site_section DROP CONSTRAINT FK_D6D798242BD701DA');
$this->addSql('ALTER TABLE site_section_image DROP CONSTRAINT FK_C90B90F82A6CBF');
$this->addSql('ALTER TABLE site_section_image DROP CONSTRAINT FK_C90B9093CB796C');
$this->addSql('ALTER TABLE site_section_banner DROP CONSTRAINT FK_648393C9F82A6CBF');
$this->addSql('ALTER TABLE site_section_banner DROP CONSTRAINT FK_648393C9684EC833');
$this->addSql('DROP TABLE site_faq');
$this->addSql('DROP TABLE site_section');
$this->addSql('DROP TABLE site_section_image');
$this->addSql('DROP TABLE site_section_banner');
$this->addSql('DROP INDEX IDX_D182A118F82A6CBF');
$this->addSql('ALTER TABLE links DROP site_section_id');
}
}