migrations/Version20250528163134.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20250528163134 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Drops and recreates std_options, std_options_permissions, std_roles, std_roles_permissions tables';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("DROP TABLE IF EXISTS std_roles_permissions");
  15.         $this->addSql("DROP TABLE IF EXISTS std_options_permissions");
  16.         $this->addSql("DROP TABLE IF EXISTS std_options");
  17.         $this->addSql("
  18.             CREATE TABLE std_options (
  19.                 id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT 'Unique identifier',
  20.                 created_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
  21.                 updated_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
  22.                 machine_name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Unique code used in the programming to identify the option',
  23.                 order_value INT DEFAULT NULL COMMENT 'Order of the option on the menu',
  24.                 path VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Url of the option',
  25.                 external_link VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Url of the option',
  26.                 is_active TINYINT(1) DEFAULT 1 COMMENT 'Flag indicating if the option is active',
  27.                 created_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time of the record creation',
  28.                 updated_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time the record was last updated',
  29.                 name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Name of the Option',
  30.                 menu_section VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Section of the option in the sidebar',
  31.                 icon VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Icon of the option in the sidebar',
  32.                 dropdown_section VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Section of the option in the sidebar',
  33.                 PRIMARY KEY(id),
  34.                 INDEX fk_std_options_std_users (created_by),
  35.                 INDEX fk_std_options_std_users_0 (updated_by),
  36.                 CONSTRAINT FK_3335B4C716FE72E1 FOREIGN KEY (updated_by) REFERENCES std_users(id),
  37.                 CONSTRAINT FK_3335B4C7DE12AB56 FOREIGN KEY (created_by) REFERENCES std_users(id)
  38.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  39.         ");
  40.         $this->addSql("
  41.             CREATE TABLE std_options_permissions (
  42.                 id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT 'Unique identifier',
  43.                 option_id INT UNSIGNED NOT NULL COMMENT 'Unique identifier',
  44.                 created_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
  45.                 updated_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
  46.                 machine_name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Code used in the programming to identify the option permission',
  47.                 name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Name of the Feature',
  48.                 description VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  49.                 bits INT UNSIGNED DEFAULT NULL COMMENT 'Value of the Feature - it has to be a power of 2 and unique for the option',
  50.                 order_value INT DEFAULT NULL COMMENT 'Order of the Feature',
  51.                 created_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time of the record creation',
  52.                 updated_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time the record was last updated',
  53.                 PRIMARY KEY(id),
  54.                 INDEX fk_std_options_permissions_std_users (created_by),
  55.                 INDEX fk_std_options_permissions_std_users_0 (updated_by),
  56.                 INDEX fk_std_options_permissions_std_options (option_id),
  57.                 CONSTRAINT FK_2158F76416FE72E1 FOREIGN KEY (updated_by) REFERENCES std_users(id),
  58.                 CONSTRAINT FK_2158F764A7C41D6F FOREIGN KEY (option_id) REFERENCES std_options(id),
  59.                 CONSTRAINT FK_2158F764DE12AB56 FOREIGN KEY (created_by) REFERENCES std_users(id)
  60.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  61.         ");
  62.         $this->addSql("
  63.             CREATE TABLE std_roles_permissions (
  64.                 option_id INT UNSIGNED NOT NULL COMMENT 'Unique identifier',
  65.                 role_id INT UNSIGNED NOT NULL COMMENT 'Role unique identifier',
  66.                 created_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
  67.                 updated_by INT UNSIGNED DEFAULT NULL COMMENT 'Unique identifier',
  68.                 permission_bits INT UNSIGNED DEFAULT NULL COMMENT 'Sum of all the permissions of the option associated to the role',
  69.                 created_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  70.                 updated_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  71.                 PRIMARY KEY(option_id, role_id),
  72.                 INDEX fk_std_roles_permissions_std_users_0 (updated_by),
  73.                 INDEX fk_std_roles_permissions_std_users (created_by),
  74.                 INDEX fk_std_roles_permissions_std_options (option_id),
  75.                 INDEX IDX_746083FCD60322AC (role_id),
  76.                 CONSTRAINT FK_746083FC16FE72E1 FOREIGN KEY (updated_by) REFERENCES std_users(id),
  77.                 CONSTRAINT FK_746083FCA7C41D6F FOREIGN KEY (option_id) REFERENCES std_options(id),
  78.                 CONSTRAINT FK_746083FCD60322AC FOREIGN KEY (role_id) REFERENCES std_roles(id),
  79.                 CONSTRAINT FK_746083FCDE12AB56 FOREIGN KEY (created_by) REFERENCES std_users(id)
  80.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  81.         ");
  82.     }
  83.     public function down(Schema $schema): void
  84.     {
  85.         $this->addSql("DROP TABLE IF EXISTS std_roles_permissions");
  86.         $this->addSql("DROP TABLE IF EXISTS std_options_permissions");
  87.         $this->addSql("DROP TABLE IF EXISTS std_options");
  88.     }
  89. }