database stuff

This commit is contained in:
2023-02-08 13:53:24 +01:00
parent ae8905e43c
commit df45cb5daa
2 changed files with 164 additions and 0 deletions

32
schema/create.sql Normal file
View File

@ -0,0 +1,32 @@
create table pv_power_measurement_t (
time timestamp without time zone not null,
deviceid text,
status text,
state integer,
importEnergyActive double precision,
importEnergyReactive double precision,
exportEnergyActive double precision,
exportEnergyReactive double precision,
powerApparent double precision,
powerActive double precision,
powerReactive double precision,
powerDemandPositive double precision,
powerDemandReverse double precision,
powerDemand double precision,
factor double precision,
angle double precision,
voltage double precision,
current double precision
);
select create_hypertable('pv_power_measurement_t', 'time');
grant insert on pv_power_measurement_t to nodered;
grant select on pv_power_measurement_t to grafana;
create view pv_stats_v as
select time, importEnergyActive, importEnergyReactive, exportEnergyActive, exportEnergyReactive,
powerApparent, powerActive, powerReactive, powerDemandPositive, powerDemandReverse, powerDemand,
factor, angle, voltage, current
from pv_power_measurement_t
order by time;