Skip to content

Commit 55837a2

Browse files
committed
feat(hk): add ownership voucher migrations and create functions
Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
1 parent 84afb35 commit 55837a2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

apps/astarte_housekeeping/lib/astarte_housekeeping/realms/queries.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ defmodule Astarte.Housekeeping.Realms.Queries do
240240
:ok <- create_simple_triggers_table(keyspace_name),
241241
:ok <- create_grouped_devices_table(keyspace_name),
242242
:ok <- create_deletion_in_progress_table(keyspace_name),
243+
:ok <- create_ownership_vouchers_table(keyspace_name),
243244
:ok <- insert_realm_public_key(keyspace_name, public_key_pem),
244245
:ok <- insert_realm_astarte_schema_version(keyspace_name),
245246
:ok <- insert_realm(realm_name, device_limit),
@@ -541,6 +542,23 @@ defmodule Astarte.Housekeeping.Realms.Queries do
541542
end
542543
end
543544

545+
defp create_ownership_vouchers_table(keyspace_name) do
546+
query = """
547+
CREATE TABLE #{keyspace_name}.ownership_vouchers (
548+
id uuid,
549+
private_key blob,
550+
voucher_data blob,
551+
expiry timestamp,
552+
553+
PRIMARY KEY (id)
554+
);
555+
"""
556+
557+
with {:ok, %{rows: nil, num_rows: 1}} <- CSystem.execute_schema_change(query) do
558+
:ok
559+
end
560+
end
561+
544562
defp create_grouped_devices_table(keyspace_name) do
545563
query = """
546564
CREATE TABLE #{keyspace_name}.grouped_devices (
@@ -665,6 +683,7 @@ defmodule Astarte.Housekeeping.Realms.Queries do
665683
attributes map<varchar, varchar>,
666684
groups map<varchar, timeuuid>,
667685
capabilities capabilities,
686+
ownership_voucher uuid,
668687
669688
PRIMARY KEY (device_id)
670689
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE :keyspace.ownership_vouchers (
2+
id uuid,
3+
private_key blob,
4+
voucher_data blob,
5+
expiry timestamp,
6+
PRIMARY KEY (id)
7+
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE :keyspace.devices
2+
ADD (
3+
ownership_voucher uuid
4+
);

0 commit comments

Comments
 (0)