<?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 Version20190808163849 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->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE TABLE user_source (group_id INT NOT NULL, source_id INT NOT NULL, INDEX IDX_3AD8644EFE54D947 (group_id), INDEX IDX_3AD8644E953C1C61 (source_id), PRIMARY KEY(group_id, source_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE group_source (group_id INT NOT NULL, source_id INT NOT NULL, INDEX IDX_8C0CA7A3FE54D947 (group_id), INDEX IDX_8C0CA7A3953C1C61 (source_id), PRIMARY KEY(group_id, source_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE user_source ADD CONSTRAINT FK_3AD8644EFE54D947 FOREIGN KEY (group_id) REFERENCES user (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE user_source ADD CONSTRAINT FK_3AD8644E953C1C61 FOREIGN KEY (source_id) REFERENCES config_source (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE group_source ADD CONSTRAINT FK_8C0CA7A3FE54D947 FOREIGN KEY (group_id) REFERENCES user_group (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE group_source ADD CONSTRAINT FK_8C0CA7A3953C1C61 FOREIGN KEY (source_id) REFERENCES config_source (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE user ADD access_all_sources TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE user_group ADD access_all_sources TINYINT(1) NOT NULL');
// give all `Administrators` access to all sources
$this->addSql('UPDATE user SET access_all_sources = 1 WHERE id = 9999 OR id IN (SELECT user_id FROM user_join_group WHERE group_id = 1)');
// give all groups access to all sources
$this->addSql('UPDATE user_group SET access_all_sources = 1');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP TABLE user_source');
$this->addSql('DROP TABLE group_source');
$this->addSql('ALTER TABLE user DROP access_all_sources');
$this->addSql('ALTER TABLE user_group DROP access_all_sources');
}
}