addSql('CREATE TABLE boot_server (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, ip VARCHAR(255) NOT NULL, api_port INT DEFAULT 8082 NOT NULL, pxe_port INT DEFAULT 8082 NOT NULL, comments VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D621FDFCD17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_IP (ip), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('ALTER TABLE client ADD boot_server_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045537E4C0FC FOREIGN KEY (boot_server_id) REFERENCES boot_server (id) ON DELETE SET NULL'); $this->addSql('CREATE INDEX IDX_C744045537E4C0FC ON client (boot_server_id)'); $this->addSql('ALTER TABLE network_settings ADD boot_server_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5437E4C0FC FOREIGN KEY (boot_server_id) REFERENCES boot_server (id) ON DELETE SET NULL'); $this->addSql('CREATE INDEX IDX_48869B5437E4C0FC ON network_settings (boot_server_id)'); $this->addSql('ALTER TABLE og_live ADD boot_server_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE og_live ADD CONSTRAINT FK_3D6B773937E4C0FC FOREIGN KEY (boot_server_id) REFERENCES boot_server (id)'); $this->addSql('CREATE INDEX IDX_3D6B773937E4C0FC ON og_live (boot_server_id)'); $this->addSql('ALTER TABLE `partition` CHANGE cache_content cache_content LONGTEXT DEFAULT NULL'); $this->addSql('ALTER TABLE pxe_template ADD boot_server_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE pxe_template ADD CONSTRAINT FK_7319755437E4C0FC FOREIGN KEY (boot_server_id) REFERENCES boot_server (id)'); $this->addSql('CREATE INDEX IDX_7319755437E4C0FC ON pxe_template (boot_server_id)'); // Extract old legacy OgBoot URL from env.json if exists, else fallback $ip = '127.0.0.1'; $envFile = __DIR__ . '/../env.json'; if (file_exists($envFile)) { $envData = json_decode(file_get_contents($envFile), true); if (isset($envData['vars']['OG_BOOT_IP'])) { $ip = $envData['vars']['OG_BOOT_IP']; } } // Create a default instance to absorb existing relations and prevent orphans $this->addSql(sprintf("INSERT INTO boot_server (uuid, created_at, updated_at, name, ip, api_port, pxe_port) VALUES (UUID(), NOW(), NOW(), 'Servidor OgBoot Local (Migrado)', '%s', 8082, 8082)", $ip)); // Relink all existing orphan properties to this newly created default server $this->addSql("UPDATE og_live SET boot_server_id = (SELECT id FROM boot_server LIMIT 1) WHERE boot_server_id IS NULL"); $this->addSql("UPDATE pxe_template SET boot_server_id = (SELECT id FROM boot_server LIMIT 1) WHERE boot_server_id IS NULL"); $this->addSql("UPDATE network_settings SET boot_server_id = (SELECT id FROM boot_server LIMIT 1) WHERE boot_server_id IS NULL"); $this->addSql("UPDATE client SET boot_server_id = (SELECT id FROM boot_server LIMIT 1) WHERE boot_server_id IS NULL"); } public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045537E4C0FC'); $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5437E4C0FC'); $this->addSql('ALTER TABLE og_live DROP FOREIGN KEY FK_3D6B773937E4C0FC'); $this->addSql('ALTER TABLE pxe_template DROP FOREIGN KEY FK_7319755437E4C0FC'); $this->addSql('DROP TABLE boot_server'); $this->addSql('DROP INDEX IDX_48869B5437E4C0FC ON network_settings'); $this->addSql('ALTER TABLE network_settings DROP boot_server_id'); $this->addSql('DROP INDEX IDX_7319755437E4C0FC ON pxe_template'); $this->addSql('ALTER TABLE pxe_template DROP boot_server_id'); $this->addSql('DROP INDEX IDX_C744045537E4C0FC ON client'); $this->addSql('ALTER TABLE client DROP boot_server_id'); $this->addSql('ALTER TABLE `partition` CHANGE cache_content cache_content VARCHAR(255) DEFAULT NULL'); $this->addSql('DROP INDEX IDX_3D6B773937E4C0FC ON og_live'); $this->addSql('ALTER TABLE og_live DROP boot_server_id'); } }