badesee-preprocessor/schema/create-schema.sql

26 lines
647 B
MySQL
Raw Normal View History

2023-01-28 18:12:57 +01:00
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');