Modificacion en el fichero migrations para que las subnets existentes les asigne un servidor dhcp por defecto al migrar
testing/ogcore-api/pipeline/head There was a failure building this commit Details
testing/ogcore-api/pipeline/pr-main There was a failure building this commit Details

pull/89/head
Juan Manuel Bardallo 2026-04-17 08:42:56 +02:00
parent 233543843a
commit 8578ff8b83
2 changed files with 27 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## [1.5.0] - 2026-04-16
### Added
- Creada nueva estructura jerárquica para administrar varios DHCPs, la clase Subnet ahora tiene una clase padre DhcpServer, de manera que tenemos una relación 1-N entre DhcpServer y Subnet (un servidor Dhcp puede tener varias Subnets)
## [1.4.2] - 2026-04-13
### Fixed
- Añadido fichero de migración con el cambio en la base de datos para añadir la fecha de despliegue de una partición.

View File

@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260414132000 extends AbstractMigration
final class Version20260417132000 extends AbstractMigration
{
public function getDescription(): string
{
@ -24,6 +24,28 @@ final class Version20260414132000 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)');
// Extract old legacy DHCP URL from env.json if exists, else fallback
$url = '127.0.0.1:8081';
$envFile = __DIR__ . '/../env.json';
if (file_exists($envFile)) {
$envData = json_decode(file_get_contents($envFile), true);
if (isset($envData['vars']['OG_DHCP_API_URL'])) {
$url = $envData['vars']['OG_DHCP_API_URL'];
}
}
// Normalize URL format before parsing since env.json stores it raw like '127.0.0.1:8081'
$url = (str_starts_with($url, 'http')) ? $url : 'http://' . $url;
$parsed = parse_url($url);
$ip = $parsed['host'] ?? '127.0.0.1';
$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));
// 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");
}
public function down(Schema $schema): void