<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250528163134 extends AbstractMigration
{
public function getDescription(): string
{
return 'Drops and recreates std_options, std_options_permissions, std_roles, std_roles_permissions tables';
}
public function up(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS std_roles_permissions");
$this->addSql("DROP TABLE IF EXISTS std_options_permissions");
$this->addSql("DROP TABLE IF EXISTS std_options");
$this->addSql("
CREATE TABLE std_options (
id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT 'Unique identifier',
created_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
updated_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
machine_name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Unique code used in the programming to identify the option',
order_value INT DEFAULT NULL COMMENT 'Order of the option on the menu',
path VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Url of the option',
external_link VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Url of the option',
is_active TINYINT(1) DEFAULT 1 COMMENT 'Flag indicating if the option is active',
created_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time of the record creation',
updated_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time the record was last updated',
name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Name of the Option',
menu_section VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Section of the option in the sidebar',
icon VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Icon of the option in the sidebar',
dropdown_section VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Section of the option in the sidebar',
PRIMARY KEY(id),
INDEX fk_std_options_std_users (created_by),
INDEX fk_std_options_std_users_0 (updated_by),
CONSTRAINT FK_3335B4C716FE72E1 FOREIGN KEY (updated_by) REFERENCES std_users(id),
CONSTRAINT FK_3335B4C7DE12AB56 FOREIGN KEY (created_by) REFERENCES std_users(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
");
$this->addSql("
CREATE TABLE std_options_permissions (
id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT 'Unique identifier',
option_id INT UNSIGNED NOT NULL COMMENT 'Unique identifier',
created_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
updated_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
machine_name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Code used in the programming to identify the option permission',
name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Name of the Feature',
description VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
bits INT UNSIGNED DEFAULT NULL COMMENT 'Value of the Feature - it has to be a power of 2 and unique for the option',
order_value INT DEFAULT NULL COMMENT 'Order of the Feature',
created_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time of the record creation',
updated_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time the record was last updated',
PRIMARY KEY(id),
INDEX fk_std_options_permissions_std_users (created_by),
INDEX fk_std_options_permissions_std_users_0 (updated_by),
INDEX fk_std_options_permissions_std_options (option_id),
CONSTRAINT FK_2158F76416FE72E1 FOREIGN KEY (updated_by) REFERENCES std_users(id),
CONSTRAINT FK_2158F764A7C41D6F FOREIGN KEY (option_id) REFERENCES std_options(id),
CONSTRAINT FK_2158F764DE12AB56 FOREIGN KEY (created_by) REFERENCES std_users(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
");
$this->addSql("
CREATE TABLE std_roles_permissions (
option_id INT UNSIGNED NOT NULL COMMENT 'Unique identifier',
role_id INT UNSIGNED NOT NULL COMMENT 'Role unique identifier',
created_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
updated_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
permission_bits INT UNSIGNED DEFAULT NULL COMMENT 'Sum of all the permissions of the option associated to the role',
created_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(option_id, role_id),
INDEX fk_std_roles_permissions_std_users_0 (updated_by),
INDEX fk_std_roles_permissions_std_users (created_by),
INDEX fk_std_roles_permissions_std_options (option_id),
INDEX IDX_746083FCD60322AC (role_id),
CONSTRAINT FK_746083FC16FE72E1 FOREIGN KEY (updated_by) REFERENCES std_users(id),
CONSTRAINT FK_746083FCA7C41D6F FOREIGN KEY (option_id) REFERENCES std_options(id),
CONSTRAINT FK_746083FCD60322AC FOREIGN KEY (role_id) REFERENCES std_roles(id),
CONSTRAINT FK_746083FCDE12AB56 FOREIGN KEY (created_by) REFERENCES std_users(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS std_roles_permissions");
$this->addSql("DROP TABLE IF EXISTS std_options_permissions");
$this->addSql("DROP TABLE IF EXISTS std_options");
}
}