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');

