

ALTER TABLE vms DROP CONSTRAINT vms_host_network_name_fkey;

ALTER TABLE host_network RENAME COLUMN network_name TO virtual_bridge_name;

ALTER TABLE host_network ADD COLUMN network_name TEXT;

UPDATE host_network SET network_name = 'public1' WHERE virtual_bridge_name = 'virbr1';
UPDATE host_network SET network_name = 'public2' WHERE virtual_bridge_name = 'virbr2';
UPDATE host_network SET network_name = 'public3' WHERE virtual_bridge_name = 'virbr3';

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

ALTER TABLE host_network ALTER COLUMN network_name SET NOT NULL;

ALTER TABLE host_network DROP CONSTRAINT host_network_pkey;
ALTER TABLE host_network ADD CONSTRAINT host_network_pkey PRIMARY KEY (host, network_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 = 17;

