2021-07-08 19:10:14 +00:00
|
|
|
|
|
|
|
CREATE TABLE host_network (
|
2021-07-09 19:13:28 +00:00
|
|
|
public_ipv4_cidr_block TEXT NOT NULL,
|
2021-07-08 19:10:14 +00:00
|
|
|
network_name TEXT NOT NULL,
|
|
|
|
host TEXT NOT NULL REFERENCES hosts(id) ON DELETE RESTRICT,
|
2021-07-12 17:16:32 +00:00
|
|
|
CONSTRAINT host_network_pkey PRIMARY KEY (host, network_name)
|
2021-07-08 19:10:14 +00:00
|
|
|
);
|
|
|
|
|
2021-07-09 19:13:28 +00:00
|
|
|
INSERT INTO host_network (host, network_name, public_ipv4_cidr_block) VALUES ('baikal', 'virbr1', '69.61.2.162/27'),
|
2021-07-12 17:16:32 +00:00
|
|
|
('baikal', 'virbr2', '69.61.2.194/26'),
|
|
|
|
('baikal', 'virbr3', '69.61.38.193/26');
|
2021-07-09 19:13:28 +00:00
|
|
|
ALTER TABLE vms RENAME COLUMN last_seen_ipv4 TO public_ipv4;
|
|
|
|
ALTER TABLE vms RENAME COLUMN last_seen_ipv6 TO public_ipv6;
|
|
|
|
ALTER TABLE vms ADD COLUMN network_name TEXT;
|
|
|
|
|
2021-07-09 19:35:23 +00:00
|
|
|
UPDATE vms SET network_name = 'virbr1' WHERE public_ipv4 < '69.61.2.192' OR public_ipv4 is NULL;
|
|
|
|
UPDATE vms SET network_name = 'virbr2' WHERE public_ipv4 >= '69.61.2.192';
|
2021-07-09 19:13:28 +00:00
|
|
|
|
|
|
|
ALTER TABLE vms ALTER COLUMN network_name SET NOT NULL;
|
|
|
|
|
2021-07-12 17:16:32 +00:00
|
|
|
ALTER TABLE vms ADD CONSTRAINT vms_host_network_name_fkey FOREIGN KEY (host, network_name)
|
|
|
|
REFERENCES host_network(host, network_name) ON DELETE RESTRICT;
|
2021-07-08 19:10:14 +00:00
|
|
|
|
2021-07-09 19:13:28 +00:00
|
|
|
|
2021-07-08 19:10:14 +00:00
|
|
|
UPDATE schemaversion SET version = 16;
|
2021-07-09 19:13:28 +00:00
|
|
|
|