<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20230929111825 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add prescriber reference relations';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE SEQUENCE IF NOT EXISTS reference_prescriber_relation_id_seq
INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE reference_prescriber_relation (
id INT NOT NULL,
code VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
)');
$this->addSql('ALTER TABLE prescriber
ADD reference_prescriber_relation_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE prescriber
ADD CONSTRAINT FK_289384BA2BACA992
FOREIGN KEY (reference_prescriber_relation_id)
REFERENCES reference_prescriber_relation (id)
NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_289384BA2BACA992
ON prescriber (reference_prescriber_relation_id)');
$this->addSql("INSERT INTO reference_prescriber_relation (id, name, code)
VALUES (1, 'reference.relation.prescriber.FRIEND', 'FRIEND'),
(2, 'reference.relation.prescriber.FAMILY', 'FAMILY'),
(3, 'reference.relation.prescriber.MERCHANT', 'MERCHANT'),
(4, 'reference.relation.prescriber.AGENT', 'AGENT'),
(5, 'reference.relation.prescriber.CONCIERGE', 'CONCIERGE'),
(6, 'reference.relation.prescriber.GUARDIAN', 'GUARDIAN'),
(7, 'reference.relation.prescriber.OTHER', 'OTHER');");
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE prescriber DROP CONSTRAINT FK_289384BA2BACA992');
$this->addSql('DROP INDEX IDX_289384BA2BACA992');
$this->addSql('ALTER TABLE prescriber DROP reference_prescriber_relation_id');
$this->addSql('DROP TABLE reference_prescriber_relation');
$this->addSql('DROP SEQUENCE IF EXISTS reference_prescriber_relation_id_seq CASCADE');
}
}