migrations/Version20260429120000.php line 1
<?phpdeclare(strict_types=1);namespace DoctrineMigrations;use Doctrine\DBAL\Schema\Schema;use Doctrine\Migrations\AbstractMigration;final class Version20260429120000 extends AbstractMigration{public function getDescription(): string{return 'Add certificate templates, rules, conditions and generated registration certificates';}public function up(Schema $schema): void{$this->abortIf(!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySQL57Platform,"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQL57Platform'.");$this->addSql('CREATE TABLE certificate_template (id INT AUTO_INCREMENT NOT NULL,title VARCHAR(255) NOT NULL,body LONGTEXT NOT NULL,active TINYINT(1) DEFAULT 1 NOT NULL,created_at DATETIME NOT NULL,updated_at DATETIME NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');$this->addSql('CREATE TABLE certificate_rule (id INT AUTO_INCREMENT NOT NULL,template_id INT NOT NULL,created_by_id INT DEFAULT NULL,updated_by_id INT DEFAULT NULL,name VARCHAR(255) NOT NULL,active TINYINT(1) DEFAULT 1 NOT NULL,requires_signature TINYINT(1) DEFAULT 0 NOT NULL,created_at DATETIME NOT NULL,updated_at DATETIME NOT NULL,INDEX IDX_CERTIFICATE_RULE_TEMPLATE (template_id),INDEX IDX_CERTIFICATE_RULE_CREATED_BY (created_by_id),INDEX IDX_CERTIFICATE_RULE_UPDATED_BY (updated_by_id),PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');$this->addSql('CREATE TABLE certificate_condition (id INT AUTO_INCREMENT NOT NULL,rule_id INT NOT NULL,qualification_type VARCHAR(30) NOT NULL,required_result VARCHAR(20) DEFAULT \'APTO\' NOT NULL,position INT DEFAULT 1 NOT NULL,INDEX IDX_CERTIFICATE_CONDITION_RULE (rule_id),PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');$this->addSql('CREATE TABLE registration_certificate (id INT AUTO_INCREMENT NOT NULL,registration_id INT NOT NULL,event_id INT NOT NULL,student_id INT NOT NULL,rule_id INT DEFAULT NULL,generated_by_id INT DEFAULT NULL,version INT NOT NULL,file_path VARCHAR(500) NOT NULL,file_hash VARCHAR(64) NOT NULL,active TINYINT(1) DEFAULT 1 NOT NULL,generated_at DATETIME NOT NULL,annulled_at DATETIME DEFAULT NULL,annulment_reason LONGTEXT DEFAULT NULL,signed TINYINT(1) DEFAULT 0 NOT NULL,signature_status VARCHAR(30) DEFAULT \'NOT_REQUIRED\' NOT NULL,signature_error LONGTEXT DEFAULT NULL,signature_certificate_fingerprint VARCHAR(128) DEFAULT NULL,signature_signed_at DATETIME DEFAULT NULL,INDEX IDX_REGISTRATION_CERTIFICATE_REGISTRATION (registration_id),INDEX idx_registration_certificate_event_active (event_id, active),INDEX IDX_REGISTRATION_CERTIFICATE_STUDENT (student_id),INDEX IDX_REGISTRATION_CERTIFICATE_RULE (rule_id),INDEX IDX_REGISTRATION_CERTIFICATE_GENERATED_BY (generated_by_id),INDEX idx_registration_certificate_active (active),PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');$this->addSql('ALTER TABLE certificate_rule ADD CONSTRAINT FK_CERTIFICATE_RULE_TEMPLATE FOREIGN KEY (template_id) REFERENCES certificate_template (id) ON DELETE CASCADE');$this->addSql('ALTER TABLE certificate_rule ADD CONSTRAINT FK_CERTIFICATE_RULE_CREATED_BY FOREIGN KEY (created_by_id) REFERENCES user (id) ON DELETE SET NULL');$this->addSql('ALTER TABLE certificate_rule ADD CONSTRAINT FK_CERTIFICATE_RULE_UPDATED_BY FOREIGN KEY (updated_by_id) REFERENCES user (id) ON DELETE SET NULL');$this->addSql('ALTER TABLE certificate_condition ADD CONSTRAINT FK_CERTIFICATE_CONDITION_RULE FOREIGN KEY (rule_id) REFERENCES certificate_rule (id) ON DELETE CASCADE');$this->addSql('ALTER TABLE registration_certificate ADD CONSTRAINT FK_REGISTRATION_CERTIFICATE_REGISTRATION FOREIGN KEY (registration_id) REFERENCES registrations (id) ON DELETE CASCADE');$this->addSql('ALTER TABLE registration_certificate ADD CONSTRAINT FK_REGISTRATION_CERTIFICATE_EVENT FOREIGN KEY (event_id) REFERENCES events (id) ON DELETE CASCADE');$this->addSql('ALTER TABLE registration_certificate ADD CONSTRAINT FK_REGISTRATION_CERTIFICATE_STUDENT FOREIGN KEY (student_id) REFERENCES user (id) ON DELETE CASCADE');$this->addSql('ALTER TABLE registration_certificate ADD CONSTRAINT FK_REGISTRATION_CERTIFICATE_RULE FOREIGN KEY (rule_id) REFERENCES certificate_rule (id) ON DELETE SET NULL');$this->addSql('ALTER TABLE registration_certificate ADD CONSTRAINT FK_REGISTRATION_CERTIFICATE_GENERATED_BY FOREIGN KEY (generated_by_id) REFERENCES user (id) ON DELETE SET NULL');}public function down(Schema $schema): void{$this->abortIf(!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySQL57Platform,"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQL57Platform'.");$this->addSql('ALTER TABLE registration_certificate DROP FOREIGN KEY FK_REGISTRATION_CERTIFICATE_REGISTRATION');$this->addSql('ALTER TABLE registration_certificate DROP FOREIGN KEY FK_REGISTRATION_CERTIFICATE_EVENT');$this->addSql('ALTER TABLE registration_certificate DROP FOREIGN KEY FK_REGISTRATION_CERTIFICATE_STUDENT');$this->addSql('ALTER TABLE registration_certificate DROP FOREIGN KEY FK_REGISTRATION_CERTIFICATE_RULE');$this->addSql('ALTER TABLE registration_certificate DROP FOREIGN KEY FK_REGISTRATION_CERTIFICATE_GENERATED_BY');$this->addSql('ALTER TABLE certificate_condition DROP FOREIGN KEY FK_CERTIFICATE_CONDITION_RULE');$this->addSql('ALTER TABLE certificate_rule DROP FOREIGN KEY FK_CERTIFICATE_RULE_TEMPLATE');$this->addSql('ALTER TABLE certificate_rule DROP FOREIGN KEY FK_CERTIFICATE_RULE_CREATED_BY');$this->addSql('ALTER TABLE certificate_rule DROP FOREIGN KEY FK_CERTIFICATE_RULE_UPDATED_BY');$this->addSql('DROP TABLE registration_certificate');$this->addSql('DROP TABLE certificate_condition');$this->addSql('DROP TABLE certificate_rule');$this->addSql('DROP TABLE certificate_template');}}