Commit b3580758 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

fixed recent-activity when one device is empty, gitignore env, db.sql & preset update

parent 6ee038d7
This diff is collapsed.
......@@ -159,12 +159,12 @@ def get_recent_activity(cur, username, n=5):
for d in devs[1]:
query += """
(SELECT timedate, appname, devname, data, utc, appkey, devid from
(SELECT utc, timedate, data from dev_{}_{} ORDER BY utc DESC limit 5) AS utc,
(SELECT '{}' as appname) AS appname,
(SELECT '{}' as appkey) AS appkey,
(SELECT '{}' as devid) AS devid,
(SELECT '{}' as devname) AS devname)
UNION ALL""".format(a[1],d[1], a[0],a[1], d[1],d[0])
(SELECT utc, timedate, data from dev_{}_{} ORDER BY utc DESC limit {}) AS utc,
(SELECT text '{}' as appname) AS appname,
(SELECT text '{}' as appkey) AS appkey,
(SELECT text '{}' as devid) AS devid,
(SELECT text '{}' as devname) AS devname)
UNION ALL""".format(a[1],d[1], n, a[0],a[1], d[1],d[0])
query = query[0:-9]
query += ' ORDER BY utc DESC LIMIT {}'.format(n)
......
CREATE TABLE public.notifications (
id VARCHAR(10) NOT NULL,
app_key VARCHAR(30) NOT NULL,
dev_id NUMERIC(3) NOT NULL,
name VARCHAR(50) NOT NULL,
description VARCHAR(300),
action_type VARCHAR(20) NOT NULL,
action VARCHAR (200) NOT NULL
);
CREATE TABLE public.notifications_queue (
nf_id VARCHAR(10) NOT NULL,
app_key VARCHAR(30) NOT NULL,
dev_id NUMERIC(3) NOT NULL,
fired_on TIMESTAMP(6) NOT NULL
);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_pkey PRIMARY KEY (id, app_key, dev_id);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_app_key_fkey FOREIGN KEY (app_key) REFERENCES public.applications(app_key);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_pkey PRIMARY KEY (nf_id, app_key, dev_id);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_app_key_fkey FOREIGN KEY (app_key, nf_id, dev_id) REFERENCES public.notifications(app_key, id, dev_id);
CREATE OR REPLACE FUNCTION nf_4e662f03_1_aaaaa()
RETURNS trigger AS
$BODY$
BEGIN
IF (NEW.data->>'temperature')::int > 70 THEN
INSERT INTO notifications_queue VALUES('aaaaa', '4e662f03', 1);
END IF;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
CREATE TRIGGER tr_4e662f03_1_aaaaa
AFTER INSERT
on dev_4e662f03_1
FOR EACH ROW
EXECUTE PROCEDURE nf_4e662f03_1_aaaaa();
......@@ -75,7 +75,8 @@ CREATE TABLE public.users (
-- last_name character varying(50),
name character varying(30) NOT NULL,
password character varying(100) NOT NULL,
role character varying(10) NOT NULL
role character varying(10) NOT NULL,
telegram_chat_id character varying(12)
);
......
......@@ -23,7 +23,7 @@ os.environ["VIRTUAL_ENV"] = base # virtual env is right above bin directory
# add the virtual environments libraries to the host python import mechanism
prev_length = len(sys.path)
for lib in "../lib/python3.5/site-packages".split(os.pathsep):
for lib in "../lib/python3.7/site-packages".split(os.pathsep):
path = os.path.realpath(os.path.join(bin_dir, lib))
site.addsitedir(path.decode("utf-8") if "" else path)
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
......
No preview for this file type
home = /usr
implementation = CPython
version_info = 3.5.3.final.0
virtualenv = 20.0.18
version_info = 3.7.3.final.0
virtualenv = 20.0.20
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
......
......@@ -5,6 +5,8 @@ source env/bin/activate
sudo apt-get install -y postgresql postgresql-contrib
sudo apt-get install -y libpq-dev
sudo apt-get install -y libssl-dev
pip install -r app/requirements.txt
sudo -u postgres psql -c "CREATE USER ${USER} WITH PASSWORD 'dev';"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment