<?php
/* @noinspection PhpUnused */
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*
* @package API
* @internal
*/
final class Version20230705102936 extends AbstractMigration
{
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE role DROP FOREIGN KEY FK_57698A6AAFC2B591');
$this->addSql('ALTER TABLE user_role DROP FOREIGN KEY FK_2DE8C6A3A76ED395');
$this->addSql('ALTER TABLE user_role DROP FOREIGN KEY FK_2DE8C6A3D60322AC');
$this->addSql('ALTER TABLE user_scope DROP FOREIGN KEY FK_E26DAE8BA76ED395');
$this->addSql('ALTER TABLE user_scope DROP FOREIGN KEY FK_E26DAE8BAFC2B591');
$this->addSql('ALTER TABLE user_scope DROP FOREIGN KEY FK_E26DAE8B8BC224C3');
$this->addSql('DROP TABLE role');
$this->addSql('DROP TABLE user_role');
$this->addSql('DROP TABLE user_scope');
}
public function getDescription(): string
{
return
"- Introduces role table.\n" .
"- Introduces permission based relation table between users and roles.\n" .
"- Introduces permission based relation table between users, modules and organizational units.";
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(
'
CREATE TABLE role (
id VARCHAR(64) NOT NULL COMMENT \'Internal role ID\',
name VARCHAR(225) NOT NULL COMMENT \'Name for role\',
module_id VARCHAR(64) NOT NULL COMMENT \'Internal module ID\',
INDEX IDX_57698A6AAFC2B591 (module_id),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
'
);
$this->addSql(
'
CREATE TABLE user_role (
user_id INT NOT NULL COMMENT \'Internal ID\',
role_id VARCHAR(64) NOT NULL COMMENT \'Internal role ID\',
INDEX IDX_2DE8C6A3A76ED395 (user_id),
INDEX IDX_2DE8C6A3D60322AC (role_id),
PRIMARY KEY(user_id, role_id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
'
);
$this->addSql(
'
CREATE TABLE user_scope (
user_id INT NOT NULL COMMENT \'Internal ID\',
module_id VARCHAR(64) NOT NULL COMMENT \'Internal module ID\',
org_unit_id INT NOT NULL COMMENT \'Internal ID\',
INDEX IDX_E26DAE8BA76ED395 (user_id),
INDEX IDX_E26DAE8BAFC2B591 (module_id),
INDEX IDX_E26DAE8B8BC224C3 (org_unit_id),
PRIMARY KEY(user_id, module_id, org_unit_id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
'
);
$this->addSql(
'
ALTER TABLE role ADD CONSTRAINT FK_57698A6AAFC2B591
FOREIGN KEY (module_id) REFERENCES module (id)
'
);
$this->addSql(
'
ALTER TABLE user_role ADD CONSTRAINT FK_2DE8C6A3A76ED395
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
'
);
$this->addSql(
'
ALTER TABLE user_role ADD CONSTRAINT FK_2DE8C6A3D60322AC
FOREIGN KEY (role_id) REFERENCES role (id)
'
);
$this->addSql(
'
ALTER TABLE user_scope ADD CONSTRAINT FK_E26DAE8BA76ED395
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;
'
);
$this->addSql(
'
ALTER TABLE user_scope ADD CONSTRAINT FK_E26DAE8BAFC2B591
FOREIGN KEY (module_id) REFERENCES module (id);
'
);
$this->addSql(
'
ALTER TABLE user_scope ADD CONSTRAINT FK_E26DAE8B8BC224C3
FOREIGN KEY (org_unit_id) REFERENCES org_unit (id) ON DELETE CASCADE;
'
);
}
}