Use ON UPDATE CASCADE for foreign keys

This commit is contained in:
ekzyis 2025-02-04 02:32:06 +01:00
parent 9745bf9b79
commit 9342a93783

View File

@ -7,7 +7,7 @@ CREATE TABLE host (
CREATE TABLE host_uptime ( CREATE TABLE host_uptime (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
host_id INT NOT NULL REFERENCES host(id), host_id INT NOT NULL REFERENCES host(id) ON UPDATE CASCADE,
-- uptime in seconds -- uptime in seconds
uptime INT NOT NULL uptime INT NOT NULL
); );
@ -16,7 +16,7 @@ CREATE INDEX host_uptime_host_id_created_at_idx ON host_uptime(host_id, created_
CREATE TABLE host_mem ( CREATE TABLE host_mem (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
host_id INT NOT NULL REFERENCES host(id), host_id INT NOT NULL REFERENCES host(id) ON UPDATE CASCADE,
-- available memory in kB -- available memory in kB
mem_avail INT NOT NULL mem_avail INT NOT NULL
); );
@ -25,7 +25,7 @@ CREATE INDEX host_mem_host_id_created_at_idx ON host_mem(host_id, created_at);
CREATE TABLE host_disk ( CREATE TABLE host_disk (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
host_id INT NOT NULL REFERENCES host(id), host_id INT NOT NULL REFERENCES host(id) ON UPDATE CASCADE,
-- free disk space in kB -- free disk space in kB
disk_free INT NOT NULL disk_free INT NOT NULL
); );
@ -34,7 +34,7 @@ CREATE INDEX host_disk_host_id_created_at_idx ON host_disk(host_id, created_at);
CREATE TABLE host_cpu ( CREATE TABLE host_cpu (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
host_id INT NOT NULL REFERENCES host(id), host_id INT NOT NULL REFERENCES host(id) ON UPDATE CASCADE,
-- cpu load for last minute -- cpu load for last minute
cpu_load_1m FLOAT NOT NULL cpu_load_1m FLOAT NOT NULL
); );