From 5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df Mon Sep 17 00:00:00 2001
From: Trygve Laugstøl <trygvis@inamo.no>
Date: Thu, 26 Feb 2015 08:43:27 +0100
Subject: o Adding utility to insert samples from json files.

---
 apps/soil-moisture.sql | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 apps/soil-moisture.sql

(limited to 'apps/soil-moisture.sql')

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;
-- 
cgit v1.2.3

