Solve error in migration
testing/ogcore-api/pipeline/head There was a failure building this commit Details
ogcore-debian-package/pipeline/head This commit looks good Details

pull/90/head
Manuel Aranda Rosales 2026-04-17 10:12:53 +02:00
parent e460d43336
commit 08ed3aa4e7
1 changed files with 11 additions and 1 deletions

View File

@ -24,6 +24,11 @@ final class Version20260417132000 extends AbstractMigration
$this->addSql('ALTER TABLE subnet ADD dhcp_server_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE subnet ADD CONSTRAINT FK_50551F51C2C88941 FOREIGN KEY (dhcp_server_id) REFERENCES dhcp_server (id)');
$this->addSql('CREATE INDEX IDX_50551F51C2C88941 ON subnet (dhcp_server_id)');
$this->addSql('ALTER TABLE dhcp_server ADD migration_id VARCHAR(255) DEFAULT NULL, ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL, ADD created_by VARCHAR(255) DEFAULT NULL, ADD updated_by VARCHAR(255) DEFAULT NULL, CHANGE api_port api_port INT DEFAULT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_BE36D128D17F50A6 ON dhcp_server (uuid)');
$this->addSql('ALTER TABLE dhcp_server RENAME INDEX uniq_identifier_ip TO UNIQ_DHCP_SERVER_IP');
$this->addSql('ALTER TABLE dhcp_server RENAME INDEX uniq_identifier_name TO UNIQ_DHCP_SERVER_NAME');
$this->addSql('ALTER TABLE subnet RENAME INDEX idx_50551f51c2c88941 TO IDX_91C24216786B311');
// Extract old legacy DHCP URL from env.json if exists, else fallback
$url = '127.0.0.1:8081';
@ -42,7 +47,7 @@ final class Version20260417132000 extends AbstractMigration
$port = isset($parsed['port']) ? $parsed['port'] : 8081;
// Create a default instance to absorb existing subnets and prevent orphans
$this->addSql(sprintf("INSERT INTO dhcp_server (name, ip, api_port, uuid) VALUES ('Servidor DHCP Local (Migrado)', '%s', %d, UUID())", $ip, $port));
$this->addSql(sprintf("INSERT INTO dhcp_server (name, ip, api_port, uuid, migration_id, created_at, updated_at, created_by, updated_by) VALUES ('Servidor DHCP Local (Migrado)', '%s', %d, UUID(), NULL, NOW(), NOW(), 'ogadmin', 'ogadmin')", $ip, $port));
// Relink all existing orphan subnets to this newly created default server
$this->addSql("UPDATE subnet SET dhcp_server_id = (SELECT id FROM dhcp_server LIMIT 1) WHERE dhcp_server_id IS NULL");
@ -55,5 +60,10 @@ final class Version20260417132000 extends AbstractMigration
$this->addSql('DROP TABLE dhcp_server');
$this->addSql('DROP INDEX IDX_50551F51C2C88941 ON subnet');
$this->addSql('ALTER TABLE subnet DROP dhcp_server_id');
$this->addSql('DROP INDEX UNIQ_BE36D128D17F50A6 ON dhcp_server');
$this->addSql('ALTER TABLE dhcp_server DROP migration_id, DROP created_at, DROP updated_at, DROP created_by, DROP updated_by, CHANGE api_port api_port INT DEFAULT 8006 NOT NULL');
$this->addSql('ALTER TABLE dhcp_server RENAME INDEX uniq_dhcp_server_ip TO UNIQ_IDENTIFIER_IP');
$this->addSql('ALTER TABLE dhcp_server RENAME INDEX uniq_dhcp_server_name TO UNIQ_IDENTIFIER_NAME');
$this->addSql('ALTER TABLE subnet RENAME INDEX idx_91c24216786b311 TO IDX_50551F51C2C88941');
}
}