43 lines
1.9 KiB
PHP
43 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
/**
|
|
* Invierte la relación Client <-> HardwareProfile de OneToOne (perfil propio
|
|
* de cada cliente) a OneToMany (un perfil de hardware compartido por varios
|
|
* clientes de una misma aula), para permitir asignarlo y propagarlo desde
|
|
* la unidad organizativa.
|
|
*/
|
|
final class Version20260710100654 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Client.hardwareProfile pasa a ser propietario de la relación (N clientes por perfil) en vez de HardwareProfile.client (1 cliente por perfil)';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE client ADD hardware_profile_id INT DEFAULT NULL');
|
|
$this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455CFA495C1 FOREIGN KEY (hardware_profile_id) REFERENCES hardware_profile (id) ON DELETE SET NULL');
|
|
$this->addSql('CREATE INDEX IDX_C7440455CFA495C1 ON client (hardware_profile_id)');
|
|
$this->addSql('ALTER TABLE hardware_profile DROP FOREIGN KEY FK_2D9A246019EB6921');
|
|
$this->addSql('DROP INDEX IDX_2D9A246019EB6921 ON hardware_profile');
|
|
$this->addSql('ALTER TABLE hardware_profile DROP client_id');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE hardware_profile ADD client_id INT NOT NULL');
|
|
$this->addSql('ALTER TABLE hardware_profile ADD CONSTRAINT FK_2D9A246019EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE');
|
|
$this->addSql('CREATE INDEX IDX_2D9A246019EB6921 ON hardware_profile (client_id)');
|
|
$this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455CFA495C1');
|
|
$this->addSql('DROP INDEX IDX_C7440455CFA495C1 ON client');
|
|
$this->addSql('ALTER TABLE client DROP hardware_profile_id');
|
|
}
|
|
}
|