migrations/Version20240222083155.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. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20240222083155 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('CREATE TABLE rights (id INT AUTO_INCREMENT NOT NULL, module_name VARCHAR(255) DEFAULT NULL, label VARCHAR(255) DEFAULT NULL, rights_code VARCHAR(255) DEFAULT NULL, is_active TINYINT(1) NOT NULL, lvl INT DEFAULT NULL, position_module INT DEFAULT NULL, position INT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  18.         $this->addSql('CREATE TABLE users_rights (user_id INT NOT NULL, rights_id INT NOT NULL, INDEX IDX_E875F93A76ED395 (user_id), INDEX IDX_E875F93B196EE6E (rights_id), PRIMARY KEY(user_id, rights_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  19.         $this->addSql('ALTER TABLE users_rights ADD CONSTRAINT FK_E875F93A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
  20.         $this->addSql('ALTER TABLE users_rights ADD CONSTRAINT FK_E875F93B196EE6E FOREIGN KEY (rights_id) REFERENCES rights (id) ON DELETE CASCADE');
  21.         $this->addSql('INSERT INTO rights (module_name, label, rights_code, is_active, lvl, position_module, position) VALUES
  22.                             ("sidebar.menu.collab", "rights.menu.collab.access", "COLLAB_ACCESS", 1, 0, 1, 1),
  23.                             ("sidebar.menu.expense", "rights.menu.expense.access", "EXPENSE_ACCESS", 1, 0, 2, 1),
  24.                             ("sidebar.menu.planning", "rights.menu.planning.access", "PLANNING_ACCESS", 1, 0, 3, 1),
  25.                             ("sidebar.menu.absence", "rights.menu.absence.access", "ABSENCE_ACCESS", 1, 0, 4, 1),
  26.                             ("sidebar.menu.score_section", "rights.menu.score_section.access", "SCORE_ACCESS", 1, 0, 5, 1),
  27.                             ("sidebar.menu.client", "rights.menu.client.access", "CLIENT_ACCESS", 1, 0, 6, 1),
  28.                             ("sidebar.menu.opportunity_global", "rights.menu.opportunity_global.access", "CRM_ACCESS", 1, 0, 7, 1),
  29.                             ("sidebar.menu.product", "rights.menu.product.access", "CATALOG_ACCESS", 1, 0, 8, 1),
  30.                             ("sidebar.menu.invoicing", "rights.menu.invoicing.access", "INVOICING_ACCESS", 1, 0, 9, 1),
  31.                             ("sidebar.menu.inventory", "rights.menu.inventory.access", "INVENTORY_ACCESS", 1, 0, 10, 1),
  32.                             ("sidebar.menu.cashflow", "rights.menu.cashflow.access", "CASHFLOW_ACCESS", 1, 0, 11, 1),
  33.                             ("sidebar.menu.project_global", "rights.menu.project_global.access", "PROJECT_ACCESS", 1, 0, 12, 2),
  34.                             ("sidebar.menu.supplier_node", "rights.menu.supplier.access", "SUPPLIERS_ACCESS", 1, 0, 13, 1)
  35.                    ');
  36.     }
  37.     public function down(Schema $schema): void
  38.     {
  39.         $this->addSql('ALTER TABLE users_rights DROP FOREIGN KEY FK_E875F93B196EE6E');
  40.         $this->addSql('DROP TABLE rights');
  41.         $this->addSql('DROP TABLE users_rights');
  42.     }
  43. }