Commit 2adb39ba6c11733ffd763e59e04ed28e6fd434f3

Authored by Volodymyr Babak
1 parent 92b78a54

code review fixes

Showing 25 changed files with 42 additions and 943 deletions
@@ -151,7 +151,6 @@ quota: @@ -151,7 +151,6 @@ quota:
151 # Enable Host API Limits 151 # Enable Host API Limits
152 enabled: "${QUOTA_TENANT_ENABLED:false}" 152 enabled: "${QUOTA_TENANT_ENABLED:false}"
153 # Array of whitelist tenants 153 # Array of whitelist tenants
154 - # Array of whitelist tenants  
155 whitelist: "${QUOTA_TENANT_WHITELIST:}" 154 whitelist: "${QUOTA_TENANT_WHITELIST:}"
156 # Array of blacklist tenants 155 # Array of blacklist tenants
157 blacklist: "${QUOTA_HOST_BLACKLIST:}" 156 blacklist: "${QUOTA_HOST_BLACKLIST:}"
@@ -160,11 +159,10 @@ quota: @@ -160,11 +159,10 @@ quota:
160 intervalMin: 2 159 intervalMin: 2
161 160
162 database: 161 database:
163 - type: "${DATABASE_TYPE:sql}" # cassandra OR sql  
164 entities: 162 entities:
165 - type: "${DATABASE_TYPE:sql}" # cassandra OR sql 163 + type: "${DATABASE_TS_TYPE:sql}" # cassandra OR sql
166 ts: 164 ts:
167 - type: "${DATABASE_TYPE:sql}" # cassandra OR sql (for hybrid mode, only this value should be cassandra) 165 + type: "${DATABASE_CASSANDRA_TYPE:sql}" # cassandra OR sql (for hybrid mode, only this value should be cassandra)
168 166
169 167
170 # Cassandra driver configuration parameters 168 # Cassandra driver configuration parameters
@@ -32,7 +32,8 @@ public class ControllerNoSqlTestSuite { @@ -32,7 +32,8 @@ public class ControllerNoSqlTestSuite {
32 public static CustomCassandraCQLUnit cassandraUnit = 32 public static CustomCassandraCQLUnit cassandraUnit =
33 new CustomCassandraCQLUnit( 33 new CustomCassandraCQLUnit(
34 Arrays.asList( 34 Arrays.asList(
35 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 35 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  36 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
36 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false), 37 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
37 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)), 38 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)),
38 "cassandra-test.yaml", 30000l); 39 "cassandra-test.yaml", 30000l);
@@ -30,7 +30,7 @@ public class ControllerSqlTestSuite { @@ -30,7 +30,7 @@ public class ControllerSqlTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties"); 35 "sql-test.properties");
36 } 36 }
@@ -32,7 +32,8 @@ public class MqttNoSqlTestSuite { @@ -32,7 +32,8 @@ public class MqttNoSqlTestSuite {
32 public static CustomCassandraCQLUnit cassandraUnit = 32 public static CustomCassandraCQLUnit cassandraUnit =
33 new CustomCassandraCQLUnit( 33 new CustomCassandraCQLUnit(
34 Arrays.asList( 34 Arrays.asList(
35 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 35 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  36 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
36 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), 37 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
37 "cassandra-test.yaml", 30000l); 38 "cassandra-test.yaml", 30000l);
38 } 39 }
@@ -15,11 +15,9 @@ @@ -15,11 +15,9 @@
15 */ 15 */
16 package org.thingsboard.server.mqtt; 16 package org.thingsboard.server.mqtt;
17 17
18 -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;  
19 import org.junit.ClassRule; 18 import org.junit.ClassRule;
20 import org.junit.extensions.cpsuite.ClasspathSuite; 19 import org.junit.extensions.cpsuite.ClasspathSuite;
21 import org.junit.runner.RunWith; 20 import org.junit.runner.RunWith;
22 -import org.thingsboard.server.dao.CustomCassandraCQLUnit;  
23 import org.thingsboard.server.dao.CustomSqlUnit; 21 import org.thingsboard.server.dao.CustomSqlUnit;
24 22
25 import java.util.Arrays; 23 import java.util.Arrays;
@@ -31,7 +29,7 @@ public class MqttSqlTestSuite { @@ -31,7 +29,7 @@ public class MqttSqlTestSuite {
31 29
32 @ClassRule 30 @ClassRule
33 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 31 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
34 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 32 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
35 "sql/drop-all-tables.sql", 33 "sql/drop-all-tables.sql",
36 "sql-test.properties"); 34 "sql-test.properties");
37 } 35 }
@@ -35,7 +35,8 @@ public class RuleEngineNoSqlTestSuite { @@ -35,7 +35,8 @@ public class RuleEngineNoSqlTestSuite {
35 public static CustomCassandraCQLUnit cassandraUnit = 35 public static CustomCassandraCQLUnit cassandraUnit =
36 new CustomCassandraCQLUnit( 36 new CustomCassandraCQLUnit(
37 Arrays.asList( 37 Arrays.asList(
38 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 38 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  39 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
39 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), 40 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
40 "cassandra-test.yaml", 30000l); 41 "cassandra-test.yaml", 30000l);
41 42
@@ -30,7 +30,7 @@ public class RuleEngineSqlTestSuite { @@ -30,7 +30,7 @@ public class RuleEngineSqlTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties"); 35 "sql-test.properties");
36 } 36 }
@@ -34,7 +34,8 @@ public class SystemNoSqlTestSuite { @@ -34,7 +34,8 @@ public class SystemNoSqlTestSuite {
34 public static CustomCassandraCQLUnit cassandraUnit = 34 public static CustomCassandraCQLUnit cassandraUnit =
35 new CustomCassandraCQLUnit( 35 new CustomCassandraCQLUnit(
36 Arrays.asList( 36 Arrays.asList(
37 - new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 37 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  38 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
38 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), 39 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
39 "cassandra-test.yaml", 30000l); 40 "cassandra-test.yaml", 30000l);
40 } 41 }
@@ -31,7 +31,7 @@ public class SystemSqlTestSuite { @@ -31,7 +31,7 @@ public class SystemSqlTestSuite {
31 31
32 @ClassRule 32 @ClassRule
33 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 33 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
34 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 34 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
35 "sql/drop-all-tables.sql", 35 "sql/drop-all-tables.sql",
36 "sql-test.properties"); 36 "sql-test.properties");
37 37
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 -package org.thingsboard.server.dao.util;  
17 -  
18 -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;  
19 -  
20 -@ConditionalOnExpression("'${database.entity.type}'=='sql' && '${database.ts.type}'=='cassandra'")  
21 -public @interface HybridDao {  
22 -}  
@@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util; @@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util;
17 17
18 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
19 19
20 -@ConditionalOnExpression("'${database.type}'=='cassandra' || '${database.ts.type}'=='cassandra'") 20 +@ConditionalOnExpression("'${database.ts.type}'=='cassandra' || '${database.entities.type}'=='cassandra'")
21 public @interface NoSqlAnyDao { 21 public @interface NoSqlAnyDao {
22 } 22 }
@@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util; @@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util;
17 17
18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
19 19
20 -@ConditionalOnProperty(prefix = "database", value = "type", havingValue = "cassandra") 20 +@ConditionalOnProperty(prefix = "database.entities", value = "type", havingValue = "cassandra")
21 public @interface NoSqlDao { 21 public @interface NoSqlDao {
22 } 22 }
@@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util; @@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util;
17 17
18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
19 19
20 -@ConditionalOnProperty(prefix = "database", value = "type", havingValue = "sql") 20 +@ConditionalOnProperty(prefix = "database.entities", value = "type", havingValue = "sql")
21 public @interface SqlDao { 21 public @interface SqlDao {
22 } 22 }
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 -CREATE KEYSPACE IF NOT EXISTS thingsboard  
18 -WITH replication = {  
19 - 'class' : 'SimpleStrategy',  
20 - 'replication_factor' : 1  
21 -};  
22 -  
23 -CREATE TABLE IF NOT EXISTS thingsboard.user (  
24 - id timeuuid,  
25 - tenant_id timeuuid,  
26 - customer_id timeuuid,  
27 - email text,  
28 - search_text text,  
29 - authority text,  
30 - first_name text,  
31 - last_name text,  
32 - additional_info text,  
33 - PRIMARY KEY (id, tenant_id, customer_id, authority)  
34 -);  
35 -  
36 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_by_email AS  
37 - SELECT *  
38 - from thingsboard.user  
39 - WHERE email IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND id IS NOT NULL AND authority IS NOT  
40 - NULL  
41 - PRIMARY KEY ( email, tenant_id, customer_id, id, authority );  
42 -  
43 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_by_tenant_and_search_text AS  
44 - SELECT *  
45 - from thingsboard.user  
46 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND authority IS NOT NULL AND search_text IS NOT NULL AND id  
47 - IS NOT NULL  
48 - PRIMARY KEY ( tenant_id, customer_id, authority, search_text, id )  
49 - WITH CLUSTERING ORDER BY ( customer_id DESC, authority DESC, search_text ASC, id DESC );  
50 -  
51 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_by_customer_and_search_text AS  
52 - SELECT *  
53 - from thingsboard.user  
54 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND authority IS NOT NULL AND search_text IS NOT NULL AND id  
55 - IS NOT NULL  
56 - PRIMARY KEY ( customer_id, tenant_id, authority, search_text, id )  
57 - WITH CLUSTERING ORDER BY ( tenant_id DESC, authority DESC, search_text ASC, id DESC );  
58 -  
59 -CREATE TABLE IF NOT EXISTS thingsboard.user_credentials (  
60 - id timeuuid PRIMARY KEY,  
61 - user_id timeuuid,  
62 - enabled boolean,  
63 - password text,  
64 - activate_token text,  
65 - reset_token text  
66 -);  
67 -  
68 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_credentials_by_user AS  
69 - SELECT *  
70 - from thingsboard.user_credentials  
71 - WHERE user_id IS NOT NULL AND id IS NOT NULL  
72 - PRIMARY KEY ( user_id, id );  
73 -  
74 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_credentials_by_activate_token AS  
75 - SELECT *  
76 - from thingsboard.user_credentials  
77 - WHERE activate_token IS NOT NULL AND id IS NOT NULL  
78 - PRIMARY KEY ( activate_token, id );  
79 -  
80 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_credentials_by_reset_token AS  
81 - SELECT *  
82 - from thingsboard.user_credentials  
83 - WHERE reset_token IS NOT NULL AND id IS NOT NULL  
84 - PRIMARY KEY ( reset_token, id );  
85 -  
86 -CREATE TABLE IF NOT EXISTS thingsboard.admin_settings (  
87 - id timeuuid PRIMARY KEY,  
88 - key text,  
89 - json_value text  
90 -);  
91 -  
92 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.admin_settings_by_key AS  
93 - SELECT *  
94 - from thingsboard.admin_settings  
95 - WHERE key IS NOT NULL AND id IS NOT NULL  
96 - PRIMARY KEY ( key, id )  
97 - WITH CLUSTERING ORDER BY ( id DESC );  
98 -  
99 -CREATE TABLE IF NOT EXISTS thingsboard.tenant (  
100 - id timeuuid,  
101 - title text,  
102 - search_text text,  
103 - region text,  
104 - country text,  
105 - state text,  
106 - city text,  
107 - address text,  
108 - address2 text,  
109 - zip text,  
110 - phone text,  
111 - email text,  
112 - additional_info text,  
113 - PRIMARY KEY (id, region)  
114 -);  
115 -  
116 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.tenant_by_region_and_search_text AS  
117 - SELECT *  
118 - from thingsboard.tenant  
119 - WHERE region IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
120 - PRIMARY KEY ( region, search_text, id )  
121 - WITH CLUSTERING ORDER BY ( search_text ASC, id DESC );  
122 -  
123 -CREATE TABLE IF NOT EXISTS thingsboard.customer (  
124 - id timeuuid,  
125 - tenant_id timeuuid,  
126 - title text,  
127 - search_text text,  
128 - country text,  
129 - state text,  
130 - city text,  
131 - address text,  
132 - address2 text,  
133 - zip text,  
134 - phone text,  
135 - email text,  
136 - additional_info text,  
137 - PRIMARY KEY (id, tenant_id)  
138 -);  
139 -  
140 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.customer_by_tenant_and_title AS  
141 - SELECT *  
142 - from thingsboard.customer  
143 - WHERE tenant_id IS NOT NULL AND title IS NOT NULL AND id IS NOT NULL  
144 - PRIMARY KEY ( tenant_id, title, id )  
145 - WITH CLUSTERING ORDER BY ( title ASC, id DESC );  
146 -  
147 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.customer_by_tenant_and_search_text AS  
148 - SELECT *  
149 - from thingsboard.customer  
150 - WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
151 - PRIMARY KEY ( tenant_id, search_text, id )  
152 - WITH CLUSTERING ORDER BY ( search_text ASC, id DESC );  
153 -  
154 -CREATE TABLE IF NOT EXISTS thingsboard.device (  
155 - id timeuuid,  
156 - tenant_id timeuuid,  
157 - customer_id timeuuid,  
158 - name text,  
159 - type text,  
160 - search_text text,  
161 - additional_info text,  
162 - PRIMARY KEY (id, tenant_id, customer_id, type)  
163 -);  
164 -  
165 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_name AS  
166 - SELECT *  
167 - from thingsboard.device  
168 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL  
169 - PRIMARY KEY ( tenant_id, name, id, customer_id, type)  
170 - WITH CLUSTERING ORDER BY ( name ASC, id DESC, customer_id DESC);  
171 -  
172 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_search_text AS  
173 - SELECT *  
174 - from thingsboard.device  
175 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
176 - PRIMARY KEY ( tenant_id, search_text, id, customer_id, type)  
177 - WITH CLUSTERING ORDER BY ( search_text ASC, id DESC, customer_id DESC);  
178 -  
179 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_by_type_and_search_text AS  
180 - SELECT *  
181 - from thingsboard.device  
182 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
183 - PRIMARY KEY ( tenant_id, type, search_text, id, customer_id)  
184 - WITH CLUSTERING ORDER BY ( type ASC, search_text ASC, id DESC, customer_id DESC);  
185 -  
186 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_and_search_text AS  
187 - SELECT *  
188 - from thingsboard.device  
189 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
190 - PRIMARY KEY ( customer_id, tenant_id, search_text, id, type )  
191 - WITH CLUSTERING ORDER BY ( tenant_id DESC, search_text ASC, id DESC );  
192 -  
193 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_by_type_and_search_text AS  
194 - SELECT *  
195 - from thingsboard.device  
196 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
197 - PRIMARY KEY ( customer_id, tenant_id, type, search_text, id )  
198 - WITH CLUSTERING ORDER BY ( tenant_id DESC, type ASC, search_text ASC, id DESC );  
199 -  
200 -CREATE TABLE IF NOT EXISTS thingsboard.device_credentials (  
201 - id timeuuid PRIMARY KEY,  
202 - device_id timeuuid,  
203 - credentials_type text,  
204 - credentials_id text,  
205 - credentials_value text  
206 -);  
207 -  
208 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_credentials_by_device AS  
209 - SELECT *  
210 - from thingsboard.device_credentials  
211 - WHERE device_id IS NOT NULL AND id IS NOT NULL  
212 - PRIMARY KEY ( device_id, id );  
213 -  
214 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_credentials_by_credentials_id AS  
215 - SELECT *  
216 - from thingsboard.device_credentials  
217 - WHERE credentials_id IS NOT NULL AND id IS NOT NULL  
218 - PRIMARY KEY ( credentials_id, id );  
219 -  
220 -CREATE TABLE IF NOT EXISTS thingsboard.asset (  
221 - id timeuuid,  
222 - tenant_id timeuuid,  
223 - customer_id timeuuid,  
224 - name text,  
225 - type text,  
226 - search_text text,  
227 - additional_info text,  
228 - PRIMARY KEY (id, tenant_id, customer_id, type)  
229 -);  
230 -  
231 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_tenant_and_name AS  
232 - SELECT *  
233 - from thingsboard.asset  
234 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL  
235 - PRIMARY KEY ( tenant_id, name, id, customer_id, type)  
236 - WITH CLUSTERING ORDER BY ( name ASC, id DESC, customer_id DESC);  
237 -  
238 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_tenant_and_search_text AS  
239 - SELECT *  
240 - from thingsboard.asset  
241 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
242 - PRIMARY KEY ( tenant_id, search_text, id, customer_id, type)  
243 - WITH CLUSTERING ORDER BY ( search_text ASC, id DESC, customer_id DESC);  
244 -  
245 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_tenant_by_type_and_search_text AS  
246 - SELECT *  
247 - from thingsboard.asset  
248 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
249 - PRIMARY KEY ( tenant_id, type, search_text, id, customer_id)  
250 - WITH CLUSTERING ORDER BY ( type ASC, search_text ASC, id DESC, customer_id DESC);  
251 -  
252 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_customer_and_search_text AS  
253 - SELECT *  
254 - from thingsboard.asset  
255 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
256 - PRIMARY KEY ( customer_id, tenant_id, search_text, id, type )  
257 - WITH CLUSTERING ORDER BY ( tenant_id DESC, search_text ASC, id DESC );  
258 -  
259 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_customer_by_type_and_search_text AS  
260 - SELECT *  
261 - from thingsboard.asset  
262 - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
263 - PRIMARY KEY ( customer_id, tenant_id, type, search_text, id )  
264 - WITH CLUSTERING ORDER BY ( tenant_id DESC, type ASC, search_text ASC, id DESC );  
265 -  
266 -CREATE TABLE IF NOT EXISTS thingsboard.entity_subtype (  
267 - tenant_id timeuuid,  
268 - entity_type text, // (DEVICE, ASSET)  
269 - type text,  
270 - PRIMARY KEY (tenant_id, entity_type, type)  
271 -);  
272 -  
273 -CREATE TABLE IF NOT EXISTS thingsboard.alarm (  
274 - id timeuuid,  
275 - tenant_id timeuuid,  
276 - type text,  
277 - originator_id timeuuid,  
278 - originator_type text,  
279 - severity text,  
280 - status text,  
281 - start_ts bigint,  
282 - end_ts bigint,  
283 - ack_ts bigint,  
284 - clear_ts bigint,  
285 - details text,  
286 - propagate boolean,  
287 - PRIMARY KEY ((tenant_id, originator_id, originator_type), type, id)  
288 -) WITH CLUSTERING ORDER BY ( type ASC, id DESC);  
289 -  
290 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.alarm_by_id AS  
291 - SELECT *  
292 - from thingsboard.alarm  
293 - WHERE tenant_id IS NOT NULL AND originator_id IS NOT NULL AND originator_type IS NOT NULL AND type IS NOT NULL  
294 - AND type IS NOT NULL AND id IS NOT NULL  
295 - PRIMARY KEY (id, tenant_id, originator_id, originator_type, type)  
296 - WITH CLUSTERING ORDER BY ( tenant_id ASC, originator_id ASC, originator_type ASC, type ASC);  
297 -  
298 -CREATE TABLE IF NOT EXISTS thingsboard.relation (  
299 - from_id timeuuid,  
300 - from_type text,  
301 - to_id timeuuid,  
302 - to_type text,  
303 - relation_type_group text,  
304 - relation_type text,  
305 - additional_info text,  
306 - PRIMARY KEY ((from_id, from_type), relation_type_group, relation_type, to_id, to_type)  
307 -) WITH CLUSTERING ORDER BY ( relation_type_group ASC, relation_type ASC, to_id ASC, to_type ASC);  
308 -  
309 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.relation_by_type_and_child_type AS  
310 - SELECT *  
311 - from thingsboard.relation  
312 - WHERE from_id IS NOT NULL AND from_type IS NOT NULL AND relation_type_group IS NOT NULL AND relation_type IS NOT NULL AND to_id IS NOT NULL AND to_type IS NOT NULL  
313 - PRIMARY KEY ((from_id, from_type), relation_type_group, relation_type, to_type, to_id)  
314 - WITH CLUSTERING ORDER BY ( relation_type_group ASC, relation_type ASC, to_type ASC, to_id DESC);  
315 -  
316 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.reverse_relation AS  
317 - SELECT *  
318 - from thingsboard.relation  
319 - WHERE from_id IS NOT NULL AND from_type IS NOT NULL AND relation_type_group IS NOT NULL AND relation_type IS NOT NULL AND to_id IS NOT NULL AND to_type IS NOT NULL  
320 - PRIMARY KEY ((to_id, to_type), relation_type_group, relation_type, from_id, from_type)  
321 - WITH CLUSTERING ORDER BY ( relation_type_group ASC, relation_type ASC, from_id ASC, from_type ASC);  
322 -  
323 -CREATE TABLE IF NOT EXISTS thingsboard.widgets_bundle (  
324 - id timeuuid,  
325 - tenant_id timeuuid,  
326 - alias text,  
327 - title text,  
328 - search_text text,  
329 - image blob,  
330 - PRIMARY KEY (id, tenant_id)  
331 -);  
332 -  
333 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.widgets_bundle_by_tenant_and_search_text AS  
334 - SELECT *  
335 - from thingsboard.widgets_bundle  
336 - WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
337 - PRIMARY KEY ( tenant_id, search_text, id )  
338 - WITH CLUSTERING ORDER BY ( search_text ASC, id DESC );  
339 -  
340 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.widgets_bundle_by_tenant_and_alias AS  
341 - SELECT *  
342 - from thingsboard.widgets_bundle  
343 - WHERE tenant_id IS NOT NULL AND alias IS NOT NULL AND id IS NOT NULL  
344 - PRIMARY KEY ( tenant_id, alias, id )  
345 - WITH CLUSTERING ORDER BY ( alias ASC, id DESC );  
346 -  
347 -CREATE TABLE IF NOT EXISTS thingsboard.widget_type (  
348 - id timeuuid,  
349 - tenant_id timeuuid,  
350 - bundle_alias text,  
351 - alias text,  
352 - name text,  
353 - descriptor text,  
354 - PRIMARY KEY (id, tenant_id, bundle_alias)  
355 -);  
356 -  
357 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.widget_type_by_tenant_and_aliases AS  
358 - SELECT *  
359 - from thingsboard.widget_type  
360 - WHERE tenant_id IS NOT NULL AND bundle_alias IS NOT NULL AND alias IS NOT NULL AND id IS NOT NULL  
361 - PRIMARY KEY ( tenant_id, bundle_alias, alias, id )  
362 - WITH CLUSTERING ORDER BY ( bundle_alias ASC, alias ASC, id DESC );  
363 -  
364 -CREATE TABLE IF NOT EXISTS thingsboard.dashboard (  
365 - id timeuuid,  
366 - tenant_id timeuuid,  
367 - title text,  
368 - search_text text,  
369 - assigned_customers text,  
370 - configuration text,  
371 - PRIMARY KEY (id, tenant_id)  
372 -);  
373 -  
374 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.dashboard_by_tenant_and_search_text AS  
375 - SELECT *  
376 - from thingsboard.dashboard  
377 - WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
378 - PRIMARY KEY ( tenant_id, search_text, id )  
379 - WITH CLUSTERING ORDER BY ( search_text ASC, id DESC );  
380 -  
381 -CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_cf (  
382 - entity_type text, // (DEVICE, CUSTOMER, TENANT)  
383 - entity_id timeuuid,  
384 - key text,  
385 - partition bigint,  
386 - ts bigint,  
387 - bool_v boolean,  
388 - str_v text,  
389 - long_v bigint,  
390 - dbl_v double,  
391 - PRIMARY KEY (( entity_type, entity_id, key, partition ), ts)  
392 -);  
393 -  
394 -CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_partitions_cf (  
395 - entity_type text, // (DEVICE, CUSTOMER, TENANT)  
396 - entity_id timeuuid,  
397 - key text,  
398 - partition bigint,  
399 - PRIMARY KEY (( entity_type, entity_id, key ), partition)  
400 -) WITH CLUSTERING ORDER BY ( partition ASC )  
401 - AND compaction = { 'class' : 'LeveledCompactionStrategy' };  
402 -  
403 -CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_latest_cf (  
404 - entity_type text, // (DEVICE, CUSTOMER, TENANT)  
405 - entity_id timeuuid,  
406 - key text,  
407 - ts bigint,  
408 - bool_v boolean,  
409 - str_v text,  
410 - long_v bigint,  
411 - dbl_v double,  
412 - PRIMARY KEY (( entity_type, entity_id ), key)  
413 -) WITH compaction = { 'class' : 'LeveledCompactionStrategy' };  
414 -  
415 -  
416 -CREATE TABLE IF NOT EXISTS thingsboard.attributes_kv_cf (  
417 - entity_type text, // (DEVICE, CUSTOMER, TENANT)  
418 - entity_id timeuuid,  
419 - attribute_type text, // (CLIENT_SIDE, SHARED, SERVER_SIDE)  
420 - attribute_key text,  
421 - bool_v boolean,  
422 - str_v text,  
423 - long_v bigint,  
424 - dbl_v double,  
425 - last_update_ts bigint,  
426 - PRIMARY KEY ((entity_type, entity_id, attribute_type), attribute_key)  
427 -) WITH compaction = { 'class' : 'LeveledCompactionStrategy' };  
428 -  
429 -CREATE TABLE IF NOT EXISTS thingsboard.component_descriptor (  
430 - id timeuuid,  
431 - type text,  
432 - scope text,  
433 - name text,  
434 - search_text text,  
435 - clazz text,  
436 - configuration_descriptor text,  
437 - actions text,  
438 - PRIMARY KEY (clazz, id, type, scope)  
439 -);  
440 -  
441 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.component_desc_by_type_search_text AS  
442 - SELECT *  
443 - from thingsboard.component_descriptor  
444 - WHERE type IS NOT NULL AND scope IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL AND clazz IS NOT NULL  
445 - PRIMARY KEY ( type, search_text, id, clazz, scope)  
446 - WITH CLUSTERING ORDER BY ( search_text DESC);  
447 -  
448 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.component_desc_by_scope_type_search_text AS  
449 - SELECT *  
450 - from thingsboard.component_descriptor  
451 - WHERE type IS NOT NULL AND scope IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL AND clazz IS NOT NULL  
452 - PRIMARY KEY ( (scope, type), search_text, id, clazz)  
453 - WITH CLUSTERING ORDER BY ( search_text DESC);  
454 -  
455 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.component_desc_by_id AS  
456 - SELECT *  
457 - from thingsboard.component_descriptor  
458 - WHERE type IS NOT NULL AND scope IS NOT NULL AND id IS NOT NULL AND clazz IS NOT NULL  
459 - PRIMARY KEY ( id, clazz, scope, type )  
460 - WITH CLUSTERING ORDER BY ( clazz ASC, scope ASC, type DESC);  
461 -  
462 -CREATE TABLE IF NOT EXISTS thingsboard.event (  
463 - tenant_id timeuuid, // tenant or system  
464 - id timeuuid,  
465 - event_type text,  
466 - event_uid text,  
467 - entity_type text,  
468 - entity_id timeuuid,  
469 - body text,  
470 - PRIMARY KEY ((tenant_id, entity_type, entity_id), event_type, event_uid)  
471 -);  
472 -  
473 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.event_by_type_and_id AS  
474 - SELECT *  
475 - FROM thingsboard.event  
476 - WHERE tenant_id IS NOT NULL AND entity_type IS NOT NULL AND entity_id IS NOT NULL AND id IS NOT NULL  
477 - AND event_type IS NOT NULL AND event_uid IS NOT NULL  
478 - PRIMARY KEY ((tenant_id, entity_type, entity_id), event_type, id, event_uid)  
479 - WITH CLUSTERING ORDER BY (event_type ASC, id ASC, event_uid ASC);  
480 -  
481 -  
482 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.event_by_id AS  
483 - SELECT *  
484 - FROM thingsboard.event  
485 - WHERE tenant_id IS NOT NULL AND entity_type IS NOT NULL AND entity_id IS NOT NULL AND id IS NOT NULL  
486 - AND event_type IS NOT NULL AND event_uid IS NOT NULL  
487 - PRIMARY KEY ((tenant_id, entity_type, entity_id), id, event_type, event_uid)  
488 - WITH CLUSTERING ORDER BY (id ASC, event_type ASC, event_uid ASC);  
489 -  
490 -CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_entity_id (  
491 - tenant_id timeuuid,  
492 - id timeuuid,  
493 - customer_id timeuuid,  
494 - entity_id timeuuid,  
495 - entity_type text,  
496 - entity_name text,  
497 - user_id timeuuid,  
498 - user_name text,  
499 - action_type text,  
500 - action_data text,  
501 - action_status text,  
502 - action_failure_details text,  
503 - PRIMARY KEY ((tenant_id, entity_id, entity_type), id)  
504 -);  
505 -  
506 -CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_customer_id (  
507 - tenant_id timeuuid,  
508 - id timeuuid,  
509 - customer_id timeuuid,  
510 - entity_id timeuuid,  
511 - entity_type text,  
512 - entity_name text,  
513 - user_id timeuuid,  
514 - user_name text,  
515 - action_type text,  
516 - action_data text,  
517 - action_status text,  
518 - action_failure_details text,  
519 - PRIMARY KEY ((tenant_id, customer_id), id)  
520 -);  
521 -  
522 -CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_user_id (  
523 - tenant_id timeuuid,  
524 - id timeuuid,  
525 - customer_id timeuuid,  
526 - entity_id timeuuid,  
527 - entity_type text,  
528 - entity_name text,  
529 - user_id timeuuid,  
530 - user_name text,  
531 - action_type text,  
532 - action_data text,  
533 - action_status text,  
534 - action_failure_details text,  
535 - PRIMARY KEY ((tenant_id, user_id), id)  
536 -);  
537 -  
538 -CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_tenant_id (  
539 - tenant_id timeuuid,  
540 - id timeuuid,  
541 - partition bigint,  
542 - customer_id timeuuid,  
543 - entity_id timeuuid,  
544 - entity_type text,  
545 - entity_name text,  
546 - user_id timeuuid,  
547 - user_name text,  
548 - action_type text,  
549 - action_data text,  
550 - action_status text,  
551 - action_failure_details text,  
552 - PRIMARY KEY ((tenant_id, partition), id)  
553 -);  
554 -  
555 -CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_tenant_id_partitions (  
556 - tenant_id timeuuid,  
557 - partition bigint,  
558 - PRIMARY KEY (( tenant_id ), partition)  
559 -) WITH CLUSTERING ORDER BY ( partition ASC )  
560 -AND compaction = { 'class' : 'LeveledCompactionStrategy' };  
561 -  
562 -CREATE TABLE IF NOT EXISTS thingsboard.msg_queue (  
563 - node_id timeuuid,  
564 - cluster_partition bigint,  
565 - ts_partition bigint,  
566 - ts bigint,  
567 - msg blob,  
568 - PRIMARY KEY ((node_id, cluster_partition, ts_partition), ts))  
569 -WITH CLUSTERING ORDER BY (ts DESC)  
570 -AND compaction = {  
571 - 'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy',  
572 - 'min_threshold': '5',  
573 - 'base_time_seconds': '43200',  
574 - 'max_window_size_seconds': '43200',  
575 - 'tombstone_threshold': '0.9',  
576 - 'unchecked_tombstone_compaction': 'true'  
577 -};  
578 -  
579 -CREATE TABLE IF NOT EXISTS thingsboard.msg_ack_queue (  
580 - node_id timeuuid,  
581 - cluster_partition bigint,  
582 - ts_partition bigint,  
583 - msg_id timeuuid,  
584 - PRIMARY KEY ((node_id, cluster_partition, ts_partition), msg_id))  
585 -WITH CLUSTERING ORDER BY (msg_id DESC)  
586 -AND compaction = {  
587 - 'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy',  
588 - 'min_threshold': '5',  
589 - 'base_time_seconds': '43200',  
590 - 'max_window_size_seconds': '43200',  
591 - 'tombstone_threshold': '0.9',  
592 - 'unchecked_tombstone_compaction': 'true'  
593 -};  
594 -  
595 -CREATE TABLE IF NOT EXISTS thingsboard.processed_msg_partitions (  
596 - node_id timeuuid,  
597 - cluster_partition bigint,  
598 - ts_partition bigint,  
599 - PRIMARY KEY ((node_id, cluster_partition), ts_partition))  
600 -WITH CLUSTERING ORDER BY (ts_partition DESC)  
601 -AND compaction = {  
602 - 'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy',  
603 - 'min_threshold': '5',  
604 - 'base_time_seconds': '43200',  
605 - 'max_window_size_seconds': '43200',  
606 - 'tombstone_threshold': '0.9',  
607 - 'unchecked_tombstone_compaction': 'true'  
608 -};  
609 -  
610 -CREATE TABLE IF NOT EXISTS thingsboard.rule_chain (  
611 - id uuid,  
612 - tenant_id uuid,  
613 - name text,  
614 - search_text text,  
615 - first_rule_node_id uuid,  
616 - root boolean,  
617 - debug_mode boolean,  
618 - configuration text,  
619 - additional_info text,  
620 - PRIMARY KEY (id, tenant_id)  
621 -);  
622 -  
623 -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.rule_chain_by_tenant_and_search_text AS  
624 - SELECT *  
625 - from thingsboard.rule_chain  
626 - WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL  
627 - PRIMARY KEY ( tenant_id, search_text, id )  
628 - WITH CLUSTERING ORDER BY ( search_text ASC, id DESC );  
629 -  
630 -CREATE TABLE IF NOT EXISTS thingsboard.rule_node (  
631 - id uuid,  
632 - rule_chain_id uuid,  
633 - type text,  
634 - name text,  
635 - debug_mode boolean,  
636 - search_text text,  
637 - configuration text,  
638 - additional_info text,  
639 - PRIMARY KEY (id)  
640 -);  
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 -  
18 -CREATE TABLE IF NOT EXISTS admin_settings (  
19 - id varchar(31) NOT NULL CONSTRAINT admin_settings_pkey PRIMARY KEY,  
20 - json_value varchar,  
21 - key varchar(255)  
22 -);  
23 -  
24 -CREATE TABLE IF NOT EXISTS alarm (  
25 - id varchar(31) NOT NULL CONSTRAINT alarm_pkey PRIMARY KEY,  
26 - ack_ts bigint,  
27 - clear_ts bigint,  
28 - additional_info varchar,  
29 - end_ts bigint,  
30 - originator_id varchar(31),  
31 - originator_type integer,  
32 - propagate boolean,  
33 - severity varchar(255),  
34 - start_ts bigint,  
35 - status varchar(255),  
36 - tenant_id varchar(31),  
37 - type varchar(255)  
38 -);  
39 -  
40 -CREATE TABLE IF NOT EXISTS asset (  
41 - id varchar(31) NOT NULL CONSTRAINT asset_pkey PRIMARY KEY,  
42 - additional_info varchar,  
43 - customer_id varchar(31),  
44 - name varchar(255),  
45 - search_text varchar(255),  
46 - tenant_id varchar(31),  
47 - type varchar(255)  
48 -);  
49 -  
50 -CREATE TABLE IF NOT EXISTS audit_log (  
51 - id varchar(31) NOT NULL CONSTRAINT audit_log_pkey PRIMARY KEY,  
52 - tenant_id varchar(31),  
53 - customer_id varchar(31),  
54 - entity_id varchar(31),  
55 - entity_type varchar(255),  
56 - entity_name varchar(255),  
57 - user_id varchar(31),  
58 - user_name varchar(255),  
59 - action_type varchar(255),  
60 - action_data varchar(1000000),  
61 - action_status varchar(255),  
62 - action_failure_details varchar(1000000)  
63 -);  
64 -  
65 -CREATE TABLE IF NOT EXISTS attribute_kv (  
66 - entity_type varchar(255),  
67 - entity_id varchar(31),  
68 - attribute_type varchar(255),  
69 - attribute_key varchar(255),  
70 - bool_v boolean,  
71 - str_v varchar(10000000),  
72 - long_v bigint,  
73 - dbl_v double precision,  
74 - last_update_ts bigint,  
75 - CONSTRAINT attribute_kv_unq_key UNIQUE (entity_type, entity_id, attribute_type, attribute_key)  
76 -);  
77 -  
78 -CREATE TABLE IF NOT EXISTS component_descriptor (  
79 - id varchar(31) NOT NULL CONSTRAINT component_descriptor_pkey PRIMARY KEY,  
80 - actions varchar(255),  
81 - clazz varchar,  
82 - configuration_descriptor varchar,  
83 - name varchar(255),  
84 - scope varchar(255),  
85 - search_text varchar(255),  
86 - type varchar(255)  
87 -);  
88 -  
89 -CREATE TABLE IF NOT EXISTS customer (  
90 - id varchar(31) NOT NULL CONSTRAINT customer_pkey PRIMARY KEY,  
91 - additional_info varchar,  
92 - address varchar,  
93 - address2 varchar,  
94 - city varchar(255),  
95 - country varchar(255),  
96 - email varchar(255),  
97 - phone varchar(255),  
98 - search_text varchar(255),  
99 - state varchar(255),  
100 - tenant_id varchar(31),  
101 - title varchar(255),  
102 - zip varchar(255)  
103 -);  
104 -  
105 -CREATE TABLE IF NOT EXISTS dashboard (  
106 - id varchar(31) NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY,  
107 - configuration varchar(10000000),  
108 - assigned_customers varchar(1000000),  
109 - search_text varchar(255),  
110 - tenant_id varchar(31),  
111 - title varchar(255)  
112 -);  
113 -  
114 -CREATE TABLE IF NOT EXISTS device (  
115 - id varchar(31) NOT NULL CONSTRAINT device_pkey PRIMARY KEY,  
116 - additional_info varchar,  
117 - customer_id varchar(31),  
118 - type varchar(255),  
119 - name varchar(255),  
120 - search_text varchar(255),  
121 - tenant_id varchar(31)  
122 -);  
123 -  
124 -CREATE TABLE IF NOT EXISTS device_credentials (  
125 - id varchar(31) NOT NULL CONSTRAINT device_credentials_pkey PRIMARY KEY,  
126 - credentials_id varchar,  
127 - credentials_type varchar(255),  
128 - credentials_value varchar,  
129 - device_id varchar(31)  
130 -);  
131 -  
132 -CREATE TABLE IF NOT EXISTS event (  
133 - id varchar(31) NOT NULL CONSTRAINT event_pkey PRIMARY KEY,  
134 - body varchar,  
135 - entity_id varchar(31),  
136 - entity_type varchar(255),  
137 - event_type varchar(255),  
138 - event_uid varchar(255),  
139 - tenant_id varchar(31),  
140 - CONSTRAINT event_unq_key UNIQUE (tenant_id, entity_type, entity_id, event_type, event_uid)  
141 -);  
142 -  
143 -CREATE TABLE IF NOT EXISTS relation (  
144 - from_id varchar(31),  
145 - from_type varchar(255),  
146 - to_id varchar(31),  
147 - to_type varchar(255),  
148 - relation_type_group varchar(255),  
149 - relation_type varchar(255),  
150 - additional_info varchar,  
151 - CONSTRAINT relation_unq_key UNIQUE (from_id, from_type, relation_type_group, relation_type, to_id, to_type)  
152 -);  
153 -  
154 -CREATE TABLE IF NOT EXISTS tb_user (  
155 - id varchar(31) NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY,  
156 - additional_info varchar,  
157 - authority varchar(255),  
158 - customer_id varchar(31),  
159 - email varchar(255) UNIQUE,  
160 - first_name varchar(255),  
161 - last_name varchar(255),  
162 - search_text varchar(255),  
163 - tenant_id varchar(31)  
164 -);  
165 -  
166 -CREATE TABLE IF NOT EXISTS tenant (  
167 - id varchar(31) NOT NULL CONSTRAINT tenant_pkey PRIMARY KEY,  
168 - additional_info varchar,  
169 - address varchar,  
170 - address2 varchar,  
171 - city varchar(255),  
172 - country varchar(255),  
173 - email varchar(255),  
174 - phone varchar(255),  
175 - region varchar(255),  
176 - search_text varchar(255),  
177 - state varchar(255),  
178 - title varchar(255),  
179 - zip varchar(255)  
180 -);  
181 -  
182 -CREATE TABLE IF NOT EXISTS ts_kv (  
183 - entity_type varchar(255) NOT NULL,  
184 - entity_id varchar(31) NOT NULL,  
185 - key varchar(255) NOT NULL,  
186 - ts bigint NOT NULL,  
187 - bool_v boolean,  
188 - str_v varchar(10000000),  
189 - long_v bigint,  
190 - dbl_v double precision,  
191 - CONSTRAINT ts_kv_unq_key UNIQUE (entity_type, entity_id, key, ts)  
192 -);  
193 -  
194 -CREATE TABLE IF NOT EXISTS ts_kv_latest (  
195 - entity_type varchar(255) NOT NULL,  
196 - entity_id varchar(31) NOT NULL,  
197 - key varchar(255) NOT NULL,  
198 - ts bigint NOT NULL,  
199 - bool_v boolean,  
200 - str_v varchar(10000000),  
201 - long_v bigint,  
202 - dbl_v double precision,  
203 - CONSTRAINT ts_kv_latest_unq_key UNIQUE (entity_type, entity_id, key)  
204 -);  
205 -  
206 -CREATE TABLE IF NOT EXISTS user_credentials (  
207 - id varchar(31) NOT NULL CONSTRAINT user_credentials_pkey PRIMARY KEY,  
208 - activate_token varchar(255) UNIQUE,  
209 - enabled boolean,  
210 - password varchar(255),  
211 - reset_token varchar(255) UNIQUE,  
212 - user_id varchar(31) UNIQUE  
213 -);  
214 -  
215 -CREATE TABLE IF NOT EXISTS widget_type (  
216 - id varchar(31) NOT NULL CONSTRAINT widget_type_pkey PRIMARY KEY,  
217 - alias varchar(255),  
218 - bundle_alias varchar(255),  
219 - descriptor varchar(1000000),  
220 - name varchar(255),  
221 - tenant_id varchar(31)  
222 -);  
223 -  
224 -CREATE TABLE IF NOT EXISTS widgets_bundle (  
225 - id varchar(31) NOT NULL CONSTRAINT widgets_bundle_pkey PRIMARY KEY,  
226 - alias varchar(255),  
227 - search_text varchar(255),  
228 - tenant_id varchar(31),  
229 - title varchar(255)  
230 -);  
231 -  
232 -CREATE TABLE IF NOT EXISTS rule_chain (  
233 - id varchar(31) NOT NULL CONSTRAINT rule_chain_pkey PRIMARY KEY,  
234 - additional_info varchar,  
235 - configuration varchar(10000000),  
236 - name varchar(255),  
237 - first_rule_node_id varchar(31),  
238 - root boolean,  
239 - debug_mode boolean,  
240 - search_text varchar(255),  
241 - tenant_id varchar(31)  
242 -);  
243 -  
244 -CREATE TABLE IF NOT EXISTS rule_node (  
245 - id varchar(31) NOT NULL CONSTRAINT rule_node_pkey PRIMARY KEY,  
246 - rule_chain_id varchar(31),  
247 - additional_info varchar,  
248 - configuration varchar(10000000),  
249 - type varchar(255),  
250 - name varchar(255),  
251 - debug_mode boolean,  
252 - search_text varchar(255)  
253 -);  
@@ -30,7 +30,7 @@ public class JpaDaoTestSuite { @@ -30,7 +30,7 @@ public class JpaDaoTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties" 35 "sql-test.properties"
36 ); 36 );
@@ -34,7 +34,9 @@ public class NoSqlDaoServiceTestSuite { @@ -34,7 +34,9 @@ public class NoSqlDaoServiceTestSuite {
34 @ClassRule 34 @ClassRule
35 public static CustomCassandraCQLUnit cassandraUnit = 35 public static CustomCassandraCQLUnit cassandraUnit =
36 new CustomCassandraCQLUnit( 36 new CustomCassandraCQLUnit(
37 - Arrays.asList(new ClassPathCQLDataSet("cassandra/schema.cql", false, false), 37 + Arrays.asList(
  38 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  39 + new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
38 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false), 40 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
39 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)), 41 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)),
40 "cassandra-test.yaml", 30000L); 42 "cassandra-test.yaml", 30000L);
@@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite { @@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit( 32 public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
33 - Arrays.asList("sql/schema.sql", "sql/system-data.sql", "sql/system-test.sql"), 33 + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql", "sql/system-test.sql"),
34 "sql/drop-all-tables.sql", 34 "sql/drop-all-tables.sql",
35 "sql-test.properties" 35 "sql-test.properties"
36 ); 36 );
1 -database.type=cassandra 1 +database.entities.type=cassandra
  2 +database.ts.type=cassandra
2 3
3 cassandra.queue.partitioning=HOURS 4 cassandra.queue.partitioning=HOURS
4 cassandra.queue.ack.ttl=3600 5 cassandra.queue.ack.ttl=3600
1 -database.type=sql 1 +database.ts.type=sql
  2 +database.entities.type=sql
2 3
3 sql.ts_inserts_executor_type=fixed 4 sql.ts_inserts_executor_type=fixed
4 sql.ts_inserts_fixed_thread_pool_size=10 5 sql.ts_inserts_fixed_thread_pool_size=10
@@ -30,7 +30,9 @@ spec: @@ -30,7 +30,9 @@ spec:
30 value: "cassandra-headless" 30 value: "cassandra-headless"
31 - name : CASSANDRA_PORT 31 - name : CASSANDRA_PORT
32 value: "9042" 32 value: "9042"
33 - - name : DATABASE_TYPE 33 + - name : DATABASE_ENTITIES_TYPE
  34 + value: "cassandra"
  35 + - name : DATABASE_TS_TYPE
34 value: "cassandra" 36 value: "cassandra"
35 - name : CASSANDRA_URL 37 - name : CASSANDRA_URL
36 value: "cassandra-headless:9042" 38 value: "cassandra-headless:9042"
@@ -30,7 +30,9 @@ spec: @@ -30,7 +30,9 @@ spec:
30 value: "cassandra-headless" 30 value: "cassandra-headless"
31 - name : CASSANDRA_PORT 31 - name : CASSANDRA_PORT
32 value: "9042" 32 value: "9042"
33 - - name : DATABASE_TYPE 33 + - name : DATABASE_ENTITIES_TYPE
  34 + value: "cassandra"
  35 + - name : DATABASE_TS_TYPE
34 value: "cassandra" 36 value: "cassandra"
35 - name : CASSANDRA_URL 37 - name : CASSANDRA_URL
36 value: "cassandra-headless:9042" 38 value: "cassandra-headless:9042"
@@ -120,7 +120,12 @@ spec: @@ -120,7 +120,12 @@ spec:
120 configMapKeyRef: 120 configMapKeyRef:
121 name: tb-config 121 name: tb-config
122 key: cassandra.url 122 key: cassandra.url
123 - - name: DATABASE_TYPE 123 + - name: DATABASE_ENTITIES_TYPE
  124 + valueFrom:
  125 + configMapKeyRef:
  126 + name: tb-config
  127 + key: database.type
  128 + - name: DATABASE_TS_TYPE
124 valueFrom: 129 valueFrom:
125 configMapKeyRef: 130 configMapKeyRef:
126 name: tb-config 131 name: tb-config
@@ -8,7 +8,8 @@ COAP_BIND_PORT=5683 @@ -8,7 +8,8 @@ COAP_BIND_PORT=5683
8 ZOOKEEPER_URL=zk:2181 8 ZOOKEEPER_URL=zk:2181
9 9
10 # type of database to use: sql[DEFAULT] or cassandra 10 # type of database to use: sql[DEFAULT] or cassandra
11 -DATABASE_TYPE=sql 11 +DATABASE_TS_TYPE=sql
  12 +DATABASE_ENTITIES_TYPE=sql
12 13
13 # cassandra db config 14 # cassandra db config
14 CASSANDRA_URL=cassandra:9042 15 CASSANDRA_URL=cassandra:9042
@@ -23,7 +23,7 @@ printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thi @@ -23,7 +23,7 @@ printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thi
23 23
24 cat /usr/share/thingsboard/conf/thingsboard.conf 24 cat /usr/share/thingsboard/conf/thingsboard.conf
25 25
26 -if [ "$DATABASE_TYPE" == "cassandra" ]; then 26 +if [ "$DATABASE_ENTITIES_TYPE" == "cassandra" ]; then
27 until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open\|filtered" 27 until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open\|filtered"
28 do 28 do
29 echo "Wait for cassandra db to start..." 29 echo "Wait for cassandra db to start..."
@@ -31,7 +31,7 @@ if [ "$DATABASE_TYPE" == "cassandra" ]; then @@ -31,7 +31,7 @@ if [ "$DATABASE_TYPE" == "cassandra" ]; then
31 done 31 done
32 fi 32 fi
33 33
34 -if [ "$DATABASE_TYPE" == "sql" ]; then 34 +if [ "$DATABASE_ENTITIES_TYPE" == "sql" ]; then
35 if [ "$SPRING_DRIVER_CLASS_NAME" == "org.postgresql.Driver" ]; then 35 if [ "$SPRING_DRIVER_CLASS_NAME" == "org.postgresql.Driver" ]; then
36 until nmap $POSTGRES_HOST -p $POSTGRES_PORT | grep "$POSTGRES_PORT/tcp open" 36 until nmap $POSTGRES_HOST -p $POSTGRES_PORT | grep "$POSTGRES_PORT/tcp open"
37 do 37 do