<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250416162440 extends AbstractMigration
{
public function getDescription(): string
{
return 'Déplace la relation avec CompanyEntity de Job vers SituationRisque';
}
public function up(Schema $schema): void
{
// Supprime la colonne company_entity_id de la table job si elle existe
if ($schema->getTable('job')->hasColumn('company_entity_id')) {
$this->addSql('ALTER TABLE job DROP company_entity_id');
}
// Ajoute la colonne company_entity_id à la table situation_risque
$this->addSql('ALTER TABLE situation_risque ADD company_entity_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE situation_risque ADD CONSTRAINT FK_A8A77A0AC1E1FD2F FOREIGN KEY (company_entity_id) REFERENCES company_entity (id)');
$this->addSql('CREATE INDEX IDX_A8A77A0AC1E1FD2F ON situation_risque (company_entity_id)');
}
public function down(Schema $schema): void
{
// Supprime la colonne company_entity_id de la table situation_risque
$this->addSql('ALTER TABLE situation_risque DROP FOREIGN KEY FK_A8A77A0AC1E1FD2F');
$this->addSql('DROP INDEX IDX_A8A77A0AC1E1FD2F ON situation_risque');
$this->addSql('ALTER TABLE situation_risque DROP company_entity_id');
// Réajoute la colonne company_entity_id à la table job
$this->addSql('ALTER TABLE job ADD company_entity_id INT NOT NULL');
$this->addSql('ALTER TABLE job ADD CONSTRAINT FK_FBD8E0F8C1E1FD2F FOREIGN KEY (company_entity_id) REFERENCES company_entity (id)');
$this->addSql('CREATE INDEX IDX_FBD8E0F8C1E1FD2F ON job (company_entity_id)');
}
}