This commit is contained in:
2023-01-28 18:12:57 +01:00
parent 30a8fe0732
commit 160cefaeeb
2 changed files with 106 additions and 7 deletions

25
schema/create-schema.sql Normal file
View File

@ -0,0 +1,25 @@
CREATE TABLE device_t {
id SERIAL NOT NULL PRIMARY KEY,
device_id VARCHAR(32) NOT NULL UNIQUE,
label VARCHAR(16) NOT NULL
};
CREATE TABLE sensor_t {
id SERIAL NOT NULL PRIMARY KEY,
address NUMERIC NOT NULL UNIQUE,
label VARCHAR(5) NOT NULL,
index SMALLINT NOT NULL,
device INTEGER NOT NULL REFERENCES device_t(id),
unique (label, device),
unique (index, device)
};
CREATE TABLE measurement_t {
time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
device_name VARCHAR(16) NOT NULL,
sensor_name VARCHAR(5) NOT NULL,
temperature DOUBLE PRECISION
};
SELECT create_hypertable('measurement_t', 'time');