From 07efa32acb1b8f489338783c7a953c9a6cfb9a73 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 23 May 2023 12:47:08 +0200 Subject: [PATCH] schema --- .gitlab-ci.yml | 7 ------ schema/create-schema.sql | 52 ++++++++++++++++++++++++++++++++++++++++ src/preprocess.py | 5 ++-- 3 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 schema/create-schema.sql diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 89db70f..3d1715c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,7 +38,6 @@ dockerize: --name $CONTAINER_NAME --restart always --network internal-network - -e "APPLICATION_TENANT=$APPLICATION_TENANT" -e "MQTT_LOGIN=$MQTT_LOGIN" -e "MQTT_PASSWORD=$MQTT_PASSWORD" -e "MQTT_BROKER=$MQTT_BROKER" @@ -49,12 +48,6 @@ dockerize: $IMAGE_NAME:$CI_COMMIT_TAG - docker network connect external-network $CONTAINER_NAME -deploy-saerbeck: - extends: .deploy - tags: - - saerbeck-deployment-only - environment: - name: saerbeck-production deploy-berresheim: extends: .deploy diff --git a/schema/create-schema.sql b/schema/create-schema.sql new file mode 100644 index 0000000..a535e4b --- /dev/null +++ b/schema/create-schema.sql @@ -0,0 +1,52 @@ +create database cem_monitoring; +-- create extension timescaledb; + + + +create table application_t ( + id serial not null primary key, + app_id VARCHAR(32) NOT NULL UNIQUE, + label varchar(128) not null unique +); + +create table variable_t ( + id serial not null primary key, + app integer references application_t(id), + converter_id varchar(16) not null, + device_id varchar(16) not null, + variable_id varchar(16) not null, + label varchar(128) not null unique, + unit varchar(16), + unique (app, converter_id, device_id, variable_id) +); + +create table measurement_t ( + time timestamp without time zone not null, + application varchar(128) not null, + variable varchar(128) not null, + unit varchar(16), + value float +); + +select create_hypertable('measurement_t', 'time'); + +insert into application_t (app_id, label) values('ku226', 'Kupferdreher Str. 226, Essen'); +insert into variable_t (app, converter_id, device_id, variable_id, label, unit) + values ((select id from application_t where app_id = 'ku226'), '1', 'bhkw', 'u', 'BHKW Spannung', 'V'), + ((select id from application_t where app_id = 'ku226'), '1', 'bhkw', 'p', 'BHKW Leistung', 'W'), + ((select id from application_t where app_id = 'ku226'), '1', 'bhkw', 'import', 'BHKW Energie Export', 'Wh'), + ((select id from application_t where app_id = 'ku226'), '1', 'bhkw', 'export', 'BHKW Energie Import', 'Wh'), + ((select id from application_t where app_id = 'ku226'), '1', 'pv', 'u', 'PV Spannung', 'V'), + ((select id from application_t where app_id = 'ku226'), '1', 'pv', 'p', 'PV Leistung', 'W'), + ((select id from application_t where app_id = 'ku226'), '1', 'pv', 'import', 'PV Energie Export', 'Wh'), + ((select id from application_t where app_id = 'ku226'), '1', 'pv', 'export', 'PV Energie Import', 'Wh') + ; + + + + +-- create user preprocessor password 'geheim'; +grant select on application_t to preprocessor; +grant select on variable_t to preprocessor; +grant insert on measurement_t to preprocessor; + diff --git a/src/preprocess.py b/src/preprocess.py index f3b7c36..f88b3c2 100644 --- a/src/preprocess.py +++ b/src/preprocess.py @@ -66,7 +66,7 @@ class DbOp(object): return application except Exception as e: logger.error(f"Error getting variable: {e}") - raise VariableNotFoundException(appId) + raise VariableNotFoundException(appId, converterId, deviceId, variableId) finally: if conn: conn.close() @@ -155,8 +155,7 @@ REQUIRED_CONFIG_OPTIONS = [ 'MQTT_PASSWORD', 'MQTT_BROKER', 'MQTT_PORT', - 'MQTT_CA', - 'APPLICATION_TENANT' + 'MQTT_CA' ] config = {}