Commit d24391a27632ed1fc638a93ffba55618a3400820

Authored by viktorbasanets
1 parent 2cc562ed

Was added update for sql and cql

  1 +/*--
  2 +-- Copyright © 2016-2018 The Thingsboard Authors
  3 +--
  4 +-- Licensed under the Apache License, Version 2.0 (the "License");
  5 +-- you may not use this file except in compliance with the License.
  6 +-- You may obtain a copy of the License at
  7 +--
  8 +-- http://www.apache.org/licenses/LICENSE-2.0
  9 +--
  10 +-- Unless required by applicable law or agreed to in writing, software
  11 +-- distributed under the License is distributed on an "AS IS" BASIS,
  12 +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 +-- See the License for the specific language governing permissions and
  14 +-- limitations under the License.
  15 +--*/
  16 +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_name;
  17 +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_entity;
  18 +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_customer;
  19 +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity;
  20 +
  21 +DROP TABLE IF EXISTS thingsboard.entity_views;
  22 +
  23 +CREATE TABLE IF NOT EXISTS thingsboard.entity_views (
  24 + id timeuuid,
  25 + entity_id timeuuid,
  26 + tenant_id timeuuid,
  27 + customer_id timeuuid,
  28 + name text,
  29 + keys text,
  30 + ts_begin bigint,
  31 + ts_end bigint,
  32 + search_text text,
  33 + additional_info text,
  34 + PRIMARY KEY (id, entity_id, tenant_id, customer_id)
  35 + );
  36 +
  37 +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS
  38 + SELECT *
  39 + from thingsboard.entity_views
  40 + WHERE entity_id IS NOT NULL
  41 + AND tenant_id IS NOT NULL
  42 + AND customer_id IS NOT NULL
  43 + AND keys IS NOT NULL
  44 + AND ts_begin IS NOT NULL
  45 + AND ts_end IS NOT NULL
  46 + AND name IS NOT NULL
  47 + AND id IS NOT NULL
  48 + PRIMARY KEY (tenant_id, name, id, entity_id, customer_id)
  49 + WITH CLUSTERING ORDER BY (name ASC, id DESC, entity_id DESC, customer_id DESC);
  50 +
  51 +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_entity AS
  52 + SELECT *
  53 + from thingsboard.entity_views
  54 + WHERE entity_id IS NOT NULL
  55 + AND tenant_id IS NOT NULL
  56 + AND customer_id IS NOT NULL
  57 + AND keys IS NOT NULL
  58 + AND ts_begin IS NOT NULL
  59 + AND ts_end IS NOT NULL
  60 + AND name IS NOT NULL
  61 + AND id IS NOT NULL
  62 + PRIMARY KEY (tenant_id, entity_id, id, customer_id, name)
  63 + WITH CLUSTERING ORDER BY (entity_id ASC, customer_id ASC, id DESC, name DESC);
  64 +
  65 +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS
  66 + SELECT *
  67 + from thingsboard.entity_views
  68 + WHERE entity_id IS NOT NULL
  69 + AND tenant_id IS NOT NULL
  70 + AND customer_id IS NOT NULL
  71 + AND keys IS NOT NULL
  72 + AND ts_begin IS NOT NULL
  73 + AND ts_end IS NOT NULL
  74 + AND name IS NOT NULL
  75 + AND id IS NOT NULL
  76 + PRIMARY KEY (tenant_id, customer_id, id, entity_id, name)
  77 + WITH CLUSTERING ORDER BY (customer_id ASC, id DESC, entity_id DESC, name DESC);
  78 +
  79 +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS
  80 + SELECT *
  81 + from thingsboard.entity_views
  82 + WHERE entity_id IS NOT NULL
  83 + AND tenant_id IS NOT NULL
  84 + AND customer_id IS NOT NULL
  85 + AND keys IS NOT NULL
  86 + AND ts_begin IS NOT NULL
  87 + AND ts_end IS NOT NULL
  88 + AND name IS NOT NULL
  89 + AND id IS NOT NULL
  90 + PRIMARY KEY (tenant_id, customer_id, entity_id, id, name)
  91 + WITH CLUSTERING ORDER BY (customer_id ASC, entity_id DESC, id DESC, name DESC);
  1 +--
  2 +-- Copyright © 2016-2018 The Thingsboard Authors
  3 +--
  4 +-- Licensed under the Apache License, Version 2.0 (the "License");
  5 +-- you may not use this file except in compliance with the License.
  6 +-- You may obtain a copy of the License at
  7 +--
  8 +-- http://www.apache.org/licenses/LICENSE-2.0
  9 +--
  10 +-- Unless required by applicable law or agreed to in writing, software
  11 +-- distributed under the License is distributed on an "AS IS" BASIS,
  12 +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 +-- See the License for the specific language governing permissions and
  14 +-- limitations under the License.
  15 +--
  16 +
  17 +DROP TABLE IF EXISTS entity_views;
  18 +
  19 +CREATE TABLE IF NOT EXISTS entity_views (
  20 + id varchar(31) NOT NULL CONSTRAINT entity_views_pkey PRIMARY KEY,
  21 + additional_info varchar,
  22 + customer_id varchar(31),
  23 + keys varchar(255),
  24 + ts_begin varchar(255),
  25 + ts_end varchar(255),
  26 + name varchar(255),
  27 + search_text varchar(255),
  28 + entity_id varchar(31),
  29 + tenant_id varchar(31)
  30 +);