-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathconsumer.sql
More file actions
84 lines (63 loc) · 2.96 KB
/
consumer.sql
File metadata and controls
84 lines (63 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
-- CONSENT MANAGEMENT DEMO, CONSUMER ACCOUNT
-- STEP 2. Run from here after running STEP 1 in PROVIDER ACCOUNT
-- Create warehouse, database, and schema for demo
use role accountadmin;
CREATE WAREHOUSE CONSENT_CONSUMER_DEMO_WH WITH WAREHOUSE_SIZE='XSmall' STATEMENT_TIMEOUT_IN_SECONDS=15 STATEMENT_QUEUED_TIMEOUT_IN_SECONDS=15;
USE WAREHOUSE CONSENT_CONSUMER_DEMO_WH;
CREATE DATABASE CONSENT_CONSUMER_DEMO;
CREATE SCHEMA CONSENT_CONSUMER_DEMO.DEMO;
USE CONSENT_CONSUMER_DEMO.DEMO;
-- show shares then create the DB from the share
show shares;
-- replace account info with data from show shares above
CREATE DATABASE CONSENT_PROV FROM SHARE <ACCOUNT INFO>.CONSENT_SHARE;
-- select to see the data shared
select * from CONSENT_PROV.demo.customer_data_view;
-- select to see if there are deletes to process
select * from CONSENT_PROV.demo.delete_requests_view;
-- create table to hold delete request ack
CREATE or replace TABLE data_deletion_ack (
deletion_request_id integer,
delete_acknowledged timestamp
);
-- share the acks back to the provider account - place provider account ID here
CREATE SHARE consent_delete_ack_share;
grant usage on database CONSENT_CONSUMER_DEMO to share consent_delete_ack_share;
grant usage on schema CONSENT_CONSUMER_DEMO.DEMO to share consent_delete_ack_share;
grant select on CONSENT_CONSUMER_DEMO.DEMO.data_deletion_ack to share consent_delete_ack_share;
alter share consent_delete_ack_share add accounts=<PROVIDER ACCOUNT HERE>;
-- task to take delete requests and process them
CREATE OR REPLACE TASK process_delete_requests
WAREHOUSE = 'CONSENT_CONSUMER_DEMO_WH'
SCHEDULE = '60 minute'
AS
EXECUTE IMMEDIATE
$$
DECLARE
delete_req_cursor cursor for select id, user_id from CONSENT_PROV.demo.delete_requests_view;
BEGIN
for record in delete_req_cursor do
-- go do the delete wherever this data has gone using record.user_id
let delete_id integer := record.id;
insert into CONSENT_CONSUMER_DEMO.DEMO.data_deletion_ack(deletion_request_id, delete_acknowledged) values (:delete_id, current_timestamp());
end for;
END;
$$;
-- END OF STEP 2. Return to the provider to execute STEP 3 and STEP 4.
-- STEP 5. Check shared data again and delete request. Process by running task.
-- select to see the data shared, notice data has changed.
select * from CONSENT_PROV.demo.customer_data_view;
-- select to see if there are deletes to process - now there is one.
select * from CONSENT_PROV.demo.delete_requests_view;
-- execute the task to process the request
EXECUTE TASK process_delete_requests;
-- verify that it made the ack (may take a little time)
select * from data_deletion_ack;
-- END OF STEP 5. Return to provider for STEP 6.
-- STEP 7. Check delete requests
-- select to see if there are deletes to process - notice we can not see acknowledged ones
select * from CONSENT_PROV.demo.delete_requests_view;
-- cleanup
ALTER TASK process_delete_requests SUSPEND;
ALTER WAREHOUSE CONSENT_CONSUMER_DEMO_WH SUSPEND;
-- END OF STEP 7