diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-19 21:53:49 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-19 21:53:49 +0200 |
commit | 73d272ffe8954b3169901eda74428bad3d2740fe (patch) | |
tree | 1f1cca7f57809e05d0c1fea7363555a5521f8bcb /migrations/sqls/20151019162208-base-up.sql | |
parent | 52eb8072664a61ea61dbdbef7485d6c81dbbcfe9 (diff) | |
download | diller-server-73d272ffe8954b3169901eda74428bad3d2740fe.tar.gz diller-server-73d272ffe8954b3169901eda74428bad3d2740fe.tar.bz2 diller-server-73d272ffe8954b3169901eda74428bad3d2740fe.tar.xz diller-server-73d272ffe8954b3169901eda74428bad3d2740fe.zip |
o Adding aggregation tables.
o Adding migration scripts for the schema.
Diffstat (limited to 'migrations/sqls/20151019162208-base-up.sql')
-rw-r--r-- | migrations/sqls/20151019162208-base-up.sql | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/migrations/sqls/20151019162208-base-up.sql b/migrations/sqls/20151019162208-base-up.sql new file mode 100644 index 0000000..97b17a6 --- /dev/null +++ b/migrations/sqls/20151019162208-base-up.sql @@ -0,0 +1,45 @@ +DROP TABLE IF EXISTS value; +DROP TABLE IF EXISTS device_property; +DROP TABLE IF EXISTS device; +DROP TABLE IF EXISTS message; + +DROP SEQUENCE IF EXISTS id_seq; + +CREATE SEQUENCE id_seq; + +CREATE TABLE message ( + timestamp TIMESTAMPTZ NOT NULL, + topic VARCHAR(1000) NOT NULL, + message BYTEA NOT NULL +); + +CREATE TABLE device ( + id BIGINT NOT NULL DEFAULT nextval('id_seq'), + key VARCHAR(1000) NOT NULL, + created_timestamp TIMESTAMPTZ NOT NULL, + name VARCHAR(1000), + description VARCHAR(1000), + + PRIMARY KEY (id), + CONSTRAINT uq_device__key UNIQUE (key) +); + +CREATE TABLE device_property ( + id BIGINT NOT NULL DEFAULT nextval('id_seq'), + device BIGINT NOT NULL REFERENCES device, + key VARCHAR(1000) NOT NULL, + created_timestamp TIMESTAMPTZ NOT NULL, + name VARCHAR(1000), + description VARCHAR(1000), + last_value VARCHAR(1000), + + PRIMARY KEY (id), + CONSTRAINT uq_device_property__key_name UNIQUE (id, name) +); + +-- no constraints! +CREATE TABLE value ( + property BIGINT NOT NULL, + timestamp TIMESTAMPTZ NOT NULL, + value VARCHAR(1000) +); |