diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-26 08:43:27 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-26 08:43:27 +0100 |
commit | 5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df (patch) | |
tree | 2fccb6a04bf62701a38617a22711f7dad23096a9 /apps/soil-moisture.sql | |
parent | 4671571c93db7f083db21cfca526ac382cdfc7ad (diff) | |
download | ble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.tar.gz ble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.tar.bz2 ble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.tar.xz ble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.zip |
o Adding utility to insert samples from json files.
Diffstat (limited to 'apps/soil-moisture.sql')
-rw-r--r-- | apps/soil-moisture.sql | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/apps/soil-moisture.sql b/apps/soil-moisture.sql new file mode 100644 index 0000000..7f16200 --- /dev/null +++ b/apps/soil-moisture.sql @@ -0,0 +1,24 @@ +DROP TABLE IF EXISTS soil_moisture_sample; +DROP TABLE IF EXISTS soil_moisture_sensor; +DROP TABLE IF EXISTS soil_moisture_device; + +DROP SEQUENCE IF EXISTS sm_id; +CREATE SEQUENCE sm_id; + +CREATE TABLE soil_moisture_device ( + id BIGINT PRIMARY KEY NOT NULL DEFAULT nextval('sm_id'), + mac VARCHAR(100) +); + +CREATE TABLE soil_moisture_sensor ( + id BIGINT PRIMARY KEY NOT NULL DEFAULT nextval('sm_id'), + device BIGINT NOT NULL REFERENCES soil_moisture_device, + sensor BIGINT NOT NULL +); + +CREATE TABLE soil_moisture_sample ( + sensor BIGINT NOT NULL REFERENCES soil_moisture_sensor, + timestamp BIGINT NOT NULL, + value BIGINT NOT NULL, + PRIMARY KEY (sensor, timestamp) +) WITHOUT OIDS; |