migrations/Version20230929111825.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 Version20230929111825 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add prescriber reference relations';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('CREATE SEQUENCE IF NOT EXISTS reference_prescriber_relation_id_seq 
  15.             INCREMENT BY 1 MINVALUE 1 START 1');
  16.         $this->addSql('CREATE TABLE reference_prescriber_relation (
  17.             id INT NOT NULL, 
  18.             code VARCHAR(255) NOT NULL, 
  19.             name VARCHAR(255) NOT NULL, 
  20.             PRIMARY KEY(id)
  21.         )');
  22.         $this->addSql('ALTER TABLE prescriber 
  23.             ADD reference_prescriber_relation_id INT DEFAULT NULL');
  24.         $this->addSql('ALTER TABLE prescriber 
  25.             ADD CONSTRAINT FK_289384BA2BACA992 
  26.             FOREIGN KEY (reference_prescriber_relation_id) 
  27.             REFERENCES reference_prescriber_relation (id) 
  28.             NOT DEFERRABLE INITIALLY IMMEDIATE');
  29.         $this->addSql('CREATE INDEX IDX_289384BA2BACA992 
  30.             ON prescriber (reference_prescriber_relation_id)');
  31.         $this->addSql("INSERT INTO reference_prescriber_relation (id, name, code) 
  32.             VALUES (1,  'reference.relation.prescriber.FRIEND', 'FRIEND'),
  33.             (2, 'reference.relation.prescriber.FAMILY', 'FAMILY'),
  34.             (3, 'reference.relation.prescriber.MERCHANT', 'MERCHANT'),
  35.             (4, 'reference.relation.prescriber.AGENT', 'AGENT'),
  36.             (5, 'reference.relation.prescriber.CONCIERGE', 'CONCIERGE'),
  37.             (6, 'reference.relation.prescriber.GUARDIAN', 'GUARDIAN'),
  38.             (7, 'reference.relation.prescriber.OTHER', 'OTHER');");
  39.     }
  40.     public function down(Schema $schema): void
  41.     {
  42.         $this->addSql('ALTER TABLE prescriber DROP CONSTRAINT FK_289384BA2BACA992');
  43.         $this->addSql('DROP INDEX IDX_289384BA2BACA992');
  44.         $this->addSql('ALTER TABLE prescriber DROP reference_prescriber_relation_id');
  45.         $this->addSql('DROP TABLE  reference_prescriber_relation');
  46.         $this->addSql('DROP SEQUENCE IF EXISTS reference_prescriber_relation_id_seq CASCADE');
  47.     }
  48. }