mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Tweak database setup
This commit is contained in:
@@ -1,30 +1,24 @@
|
|||||||
INSERT INTO
|
INSERT INTO reading(
|
||||||
reading
|
time,
|
||||||
(
|
name,
|
||||||
time,
|
model,
|
||||||
name,
|
temperature,
|
||||||
model,
|
pressure,
|
||||||
temperature,
|
humidity,
|
||||||
pressure,
|
luminance,
|
||||||
humidity,
|
gas_resistance,
|
||||||
luminance,
|
color_temperature,
|
||||||
gas_resistance,
|
air_quality_index)
|
||||||
color_temperature,
|
VALUES (
|
||||||
air_quality_index
|
@Timestamp,
|
||||||
)
|
@Name,
|
||||||
VALUES
|
@Model,
|
||||||
(
|
@Temperature,
|
||||||
@Timestamp,
|
@Pressure,
|
||||||
@Name,
|
@Humidity,
|
||||||
@Model,
|
@Luminance,
|
||||||
@Temperature,
|
@GasResistance,
|
||||||
@Pressure,
|
@ColorTemperature,
|
||||||
@Humidity,
|
@AirQualityIndex)
|
||||||
@Luminance,
|
|
||||||
@GasResistance,
|
|
||||||
@ColorTemperature,
|
|
||||||
@AirQualityIndex
|
|
||||||
)
|
|
||||||
ON CONFLICT
|
ON CONFLICT
|
||||||
ON CONSTRAINT reading_pk
|
DO NOTHING
|
||||||
DO NOTHING
|
|
||||||
|
|||||||
@@ -1,17 +1,26 @@
|
|||||||
CREATE TABLE
|
CREATE EXTENSION IF NOT EXISTS timescaledb;
|
||||||
reading (
|
|
||||||
time timestamptz NOT NULL,
|
CREATE TABLE reading(
|
||||||
name text NOT NULL,
|
time timestamptz NOT NULL,
|
||||||
model text NOT NULL,
|
name text NOT NULL,
|
||||||
temperature DECIMAL NOT NULL,
|
model text NOT NULL,
|
||||||
pressure DECIMAL NOT NULL,
|
temperature DECIMAL NOT NULL,
|
||||||
humidity DECIMAL NOT NULL,
|
pressure DECIMAL NOT NULL,
|
||||||
luminance INT NOT NULL,
|
humidity DECIMAL NOT NULL,
|
||||||
gas_resistance INT NOT NULL,
|
luminance int NOT NULL,
|
||||||
color_temperature INT NOT NULL,
|
gas_resistance int NOT NULL,
|
||||||
air_quality_index DECIMAL NOT NULL,
|
color_temperature int NOT NULL,
|
||||||
CONSTRAINT reading_pk PRIMARY KEY (time, name, model)
|
air_quality_index DECIMAL NOT NULL,
|
||||||
);
|
CONSTRAINT reading_pk PRIMARY KEY (time, name, model)
|
||||||
|
);
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
create_hypertable('reading', by_range('time'));
|
create_hypertable('reading', by_range('time'));
|
||||||
|
|
||||||
|
ALTER TABLE reading SET (
|
||||||
|
timescaledb.compress,
|
||||||
|
timescaledb.compress_segmentby = 'name, model',
|
||||||
|
timescaledb.compress_orderby = 'time DESC');
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
add_compression_policy('reading', INTERVAL '7 days');
|
||||||
|
|||||||
Reference in New Issue
Block a user