Skip to content

Commit 48fc74a

Browse files
committed
chore: add ownership_vouchers table and device ref on all db helpers
Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
1 parent 3c77969 commit 48fc74a

File tree

10 files changed

+121
-5
lines changed

10 files changed

+121
-5
lines changed

apps/astarte_appengine_api/test/support/helpers/database.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ defmodule Astarte.Helpers.Database do
107107
);
108108
"""
109109

110+
@create_ownership_vouchers_table """
111+
CREATE TABLE #{Realm.keyspace_name(@test_realm)}.ownership_vouchers (
112+
id uuid,
113+
private_key blob,
114+
voucher_data blob,
115+
expiry timestamp,
116+
PRIMARY KEY (id)
117+
);
118+
"""
119+
110120
@create_devices_table """
111121
CREATE TABLE #{Realm.keyspace_name(@test_realm)}.devices (
112122
device_id uuid,
@@ -134,6 +144,7 @@ defmodule Astarte.Helpers.Database do
134144
attributes map<varchar, varchar>,
135145
groups map<text, timeuuid>,
136146
capabilities capabilities,
147+
ownership_voucher uuid,
137148
138149
PRIMARY KEY (device_id)
139150
);
@@ -433,6 +444,8 @@ defmodule Astarte.Helpers.Database do
433444
{:ok, _} ->
434445
Repo.query!(@create_capabilities_type)
435446

447+
Repo.query!(@create_ownership_vouchers_table)
448+
436449
Repo.query!(@create_devices_table)
437450

438451
Repo.query!(@create_deletion_in_progress_table)

apps/astarte_appengine_api/test/support/helpers/database_v2.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ defmodule Astarte.Helpers.DatabaseV2 do
6666
purge_properties_compression_format int
6767
);
6868
"""
69+
@create_ownership_vouchers_table """
70+
CREATE TABLE :keyspace.ownership_vouchers (
71+
id uuid,
72+
private_key blob,
73+
voucher_data blob,
74+
expiry timestamp,
75+
PRIMARY KEY (id)
76+
);
77+
"""
6978

7079
@create_devices_table """
7180
CREATE TABLE :keyspace.devices (
@@ -95,6 +104,7 @@ defmodule Astarte.Helpers.DatabaseV2 do
95104
capabilities capabilities,
96105
97106
groups map<text, timeuuid>,
107+
ownership_voucher uuid,
98108
99109
PRIMARY KEY (device_id)
100110
)
@@ -247,6 +257,7 @@ defmodule Astarte.Helpers.DatabaseV2 do
247257
realm_keyspace = Realm.keyspace_name(realm_name)
248258
execute!(realm_keyspace, @create_keyspace)
249259
execute!(realm_keyspace, @create_capabilities_type)
260+
execute!(realm_keyspace, @create_ownership_vouchers_table)
250261
execute!(realm_keyspace, @create_devices_table)
251262
execute!(realm_keyspace, @create_groups_table)
252263
execute!(realm_keyspace, @create_names_table)

apps/astarte_data_updater_plant/test/support/database_test_helper.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ defmodule Astarte.DataUpdaterPlant.DatabaseTestHelper do
5050
);
5151
"""
5252

53+
@create_ownership_vouchers_table """
54+
CREATE TABLE :keyspace.ownership_vouchers (
55+
id uuid,
56+
private_key blob,
57+
voucher_data blob,
58+
expiry timestamp,
59+
PRIMARY KEY (id)
60+
);
61+
"""
62+
5363
@create_devices_table """
5464
CREATE TABLE :keyspace.devices (
5565
device_id uuid,
@@ -77,6 +87,7 @@ defmodule Astarte.DataUpdaterPlant.DatabaseTestHelper do
7787
attributes map<varchar, varchar>,
7888
groups map<text, timeuuid>,
7989
capabilities capabilities,
90+
ownership_voucher uuid,
8091
8192
PRIMARY KEY (device_id)
8293
);
@@ -366,6 +377,7 @@ defmodule Astarte.DataUpdaterPlant.DatabaseTestHelper do
366377
case execute(keyspace_name, @create_autotestrealm) do
367378
{:ok, _} ->
368379
execute!(keyspace_name, @create_capabilities_type)
380+
execute!(keyspace_name, @create_ownership_vouchers_table)
369381
execute!(keyspace_name, @create_devices_table)
370382
execute!(keyspace_name, @create_endpoints_table)
371383

apps/astarte_data_updater_plant/test/support/helpers/database.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ defmodule Astarte.Helpers.Database do
7070
purge_properties_compression_format int
7171
);
7272
"""
73+
@create_ownership_vouchers_table """
74+
CREATE TABLE :keyspace.ownership_vouchers (
75+
id uuid,
76+
private_key blob,
77+
voucher_data blob,
78+
expiry timestamp,
79+
PRIMARY KEY (id)
80+
);
81+
"""
7382

7483
@create_devices_table """
7584
CREATE TABLE :keyspace.devices (
@@ -96,7 +105,8 @@ defmodule Astarte.Helpers.Database do
96105
last_credentials_request_ip inet,
97106
last_seen_ip inet,
98107
attributes map<varchar, varchar>,
99-
capabilities capabilities,
108+
capabilities capabilities,
109+
ownership_voucher uuid,
100110
101111
groups map<text, timeuuid>,
102112
@@ -305,6 +315,7 @@ defmodule Astarte.Helpers.Database do
305315
realm_keyspace = Realm.keyspace_name(realm_name)
306316
execute!(realm_keyspace, @create_keyspace)
307317
execute!(realm_keyspace, @create_capabilities_type)
318+
execute!(realm_keyspace, @create_ownership_vouchers_table)
308319
execute!(realm_keyspace, @create_devices_table)
309320
execute!(realm_keyspace, @create_groups_table)
310321
execute!(realm_keyspace, @create_names_table)

apps/astarte_housekeeping/test/support/helpers/database.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ defmodule Astarte.Housekeeping.Helpers.Database do
6767
purge_properties_compression_format int
6868
);
6969
"""
70+
@create_ownership_vouchers_table """
71+
CREATE TABLE :keyspace.ownership_vouchers (
72+
id uuid,
73+
private_key blob,
74+
voucher_data blob,
75+
expiry timestamp,
76+
PRIMARY KEY (id)
77+
);
78+
"""
7079

7180
@create_devices_table """
7281
CREATE TABLE :keyspace.devices (
@@ -95,6 +104,7 @@ defmodule Astarte.Housekeeping.Helpers.Database do
95104
attributes map<varchar, varchar>,
96105
groups map<text, timeuuid>,
97106
capabilities capabilities,
107+
ownership_voucher uuid,
98108
99109
PRIMARY KEY (device_id)
100110
)
@@ -325,6 +335,7 @@ defmodule Astarte.Housekeeping.Helpers.Database do
325335
realm_keyspace = Realm.keyspace_name(realm_name)
326336
execute(realm_keyspace, @create_keyspace)
327337
execute(realm_keyspace, @create_capabilities_type)
338+
execute(realm_keyspace, @create_ownership_vouchers_table)
328339
execute(realm_keyspace, @create_devices_table)
329340
execute(realm_keyspace, @create_groups_table)
330341
execute(realm_keyspace, @create_names_table)

apps/astarte_pairing/test/support/helpers/database.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ defmodule Astarte.Helpers.Database do
7474
);
7575
"""
7676

77+
@create_ownership_vouchers_table """
78+
CREATE TABLE :keyspace.ownership_vouchers (
79+
id uuid,
80+
private_key blob,
81+
voucher_data blob,
82+
expiry timestamp,
83+
PRIMARY KEY (id)
84+
);
85+
"""
86+
7787
@create_devices_table """
7888
CREATE TABLE :keyspace.devices (
7989
device_id uuid,
@@ -102,6 +112,7 @@ defmodule Astarte.Helpers.Database do
102112
capabilities capabilities,
103113
104114
groups map<text, timeuuid>,
115+
ownership_voucher uuid,
105116
106117
PRIMARY KEY (device_id)
107118
)
@@ -284,6 +295,7 @@ defmodule Astarte.Helpers.Database do
284295
realm_keyspace = Realm.keyspace_name(realm_name)
285296
execute!(realm_keyspace, @create_keyspace)
286297
execute!(realm_keyspace, @create_capabilities_type)
298+
execute!(realm_keyspace, @create_ownership_vouchers_table)
287299
execute!(realm_keyspace, @create_devices_table)
288300
execute!(realm_keyspace, @create_groups_table)
289301
execute!(realm_keyspace, @create_names_table)

apps/astarte_realm_management/test/support/helpers/database.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ defmodule Astarte.Helpers.Database do
6767
);
6868
"""
6969

70+
@create_ownership_vouchers_table """
71+
CREATE TABLE IF NOT EXISTS :keyspace.ownership_vouchers (
72+
id uuid,
73+
private_key blob,
74+
voucher_data blob,
75+
expiry timestamp,
76+
PRIMARY KEY (id)
77+
);
78+
"""
79+
7080
@create_devices_table """
7181
CREATE TABLE IF NOT EXISTS :keyspace.devices (
7282
device_id uuid,
@@ -93,8 +103,8 @@ defmodule Astarte.Helpers.Database do
93103
last_seen_ip inet,
94104
attributes map<varchar, varchar>,
95105
capabilities capabilities,
96-
97106
groups map<text, timeuuid>,
107+
ownership_voucher uuid,
98108
99109
PRIMARY KEY (device_id)
100110
)
@@ -262,6 +272,7 @@ defmodule Astarte.Helpers.Database do
262272
realm_keyspace = Realm.keyspace_name(realm_name)
263273
execute!(realm_keyspace, @create_keyspace)
264274
execute!(realm_keyspace, @create_capabilities_type)
275+
execute!(realm_keyspace, @create_ownership_vouchers_table)
265276
execute!(realm_keyspace, @create_devices_table)
266277
execute!(realm_keyspace, @create_groups_table)
267278
execute!(realm_keyspace, @create_names_table)

apps/astarte_trigger_engine/test/support/helpers/database.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ defmodule Astarte.Helpers.Database do
6666
);
6767
"""
6868

69+
@create_ownership_vouchers_table """
70+
CREATE TABLE :keyspace.ownership_vouchers (
71+
id uuid,
72+
private_key blob,
73+
voucher_data blob,
74+
expiry timestamp,
75+
PRIMARY KEY (id)
76+
);
77+
"""
78+
6979
@create_devices_table """
7080
CREATE TABLE :keyspace.devices (
7181
device_id uuid,
@@ -92,8 +102,8 @@ defmodule Astarte.Helpers.Database do
92102
last_seen_ip inet,
93103
attributes map<varchar, varchar>,
94104
capabilities capabilities,
95-
96105
groups map<text, timeuuid>,
106+
ownership_voucher uuid,
97107
98108
PRIMARY KEY (device_id)
99109
)
@@ -223,6 +233,7 @@ defmodule Astarte.Helpers.Database do
223233
realm_keyspace = Realm.keyspace_name(realm_name)
224234
execute!(realm_keyspace, @create_keyspace)
225235
execute!(realm_keyspace, @create_capabilities_type)
236+
execute!(realm_keyspace, @create_ownership_vouchers_table)
226237
execute!(realm_keyspace, @create_devices_table)
227238
execute!(realm_keyspace, @create_groups_table)
228239
execute!(realm_keyspace, @create_names_table)

libs/astarte_data_access/test/support/database_test_helper.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
5757
);
5858
"""
5959

60+
@create_ownership_vouchers_table """
61+
CREATE TABLE :keyspace.ownership_vouchers (
62+
id uuid,
63+
private_key blob,
64+
voucher_data blob,
65+
expiry timestamp,
66+
PRIMARY KEY (id)
67+
);
68+
"""
69+
6070
@create_devices_table """
6171
CREATE TABLE autotestrealm.devices (
6272
device_id uuid,
@@ -83,6 +93,7 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
8393
last_seen_ip inet,
8494
attributes map<varchar, varchar>,
8595
groups map<text, timeuuid>,
96+
ownership_voucher uuid,
8697
8798
PRIMARY KEY (device_id)
8899
);
@@ -403,6 +414,7 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
403414
def create_test_keyspace(conn) do
404415
case Xandra.execute(conn, @create_autotestrealm) do
405416
{:ok, _} ->
417+
Xandra.execute!(conn, @create_ownership_vouchers_table)
406418
Xandra.execute!(conn, @create_devices_table)
407419
Xandra.execute!(conn, @create_names_table)
408420
Xandra.execute!(conn, @create_kv_store)

tools/astarte_export/test/database_test.exs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ defmodule Astarte.DatabaseTestdata do
3434
PRIMARY KEY ((group_name), insertion_uuid, device_id)
3535
);
3636
"""
37-
37+
38+
@create_ownership_vouchers_table """
39+
CREATE TABLE :keyspace.ownership_vouchers (
40+
id uuid,
41+
private_key blob,
42+
voucher_data blob,
43+
expiry timestamp,
44+
PRIMARY KEY (id)
45+
);
46+
"""
47+
3848
@create_devices_table """
3949
CREATE TABLE test.devices (
4050
device_id uuid PRIMARY KEY,
@@ -59,7 +69,8 @@ defmodule Astarte.DatabaseTestdata do
5969
pending_empty_cache boolean,
6070
protocol_revision int,
6171
total_received_bytes bigint,
62-
total_received_msgs bigint
72+
total_received_msgs bigint,
73+
ownership_voucher uuid,
6374
)
6475
"""
6576
@create_interfaces_table """
@@ -336,6 +347,7 @@ defmodule Astarte.DatabaseTestdata do
336347
@create_kv_store,
337348
@create_names_table,
338349
@create_groups_table,
350+
@create_ownership_vouchers_table,
339351
@create_devices_table,
340352
@create_interfaces_table,
341353
@create_endpoints_table,

0 commit comments

Comments
 (0)