

ALTER TABLE vms DROP CONSTRAINT vms_host_network_name_fkey;

UPDATE host_network SET network_name = 'virbr1' WHERE virtual_bridge_name = "virbr1";
UPDATE host_network SET network_name = 'virbr2' WHERE virtual_bridge_name = "virbr1";
UPDATE host_network SET network_name = 'virbr3' WHERE virtual_bridge_name = "virbr2";

UPDATE vms SET network_name = 'virbr1' WHERE network_name = "public1";
UPDATE vms SET network_name = 'virbr2' WHERE network_name = "public2";
UPDATE vms SET network_name = 'virbr3' WHERE network_name = "public3";

ALTER TABLE host_network DROP COLUMN virtual_bridge_name;

ALTER TABLE vms ADD CONSTRAINT vms_host_network_name_fkey FOREIGN KEY (host, network_name) 
                                               REFERENCES host_network(host, network_name) ON DELETE RESTRICT;

UPDATE schemaversion SET version = 16;
