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
|
|
-); |