forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 1
/
0025-downgrade.sql
47 lines (40 loc) · 1.41 KB
/
0025-downgrade.sql
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
begin
lock table roles;
raise log 'TIMING start roles_entities create table';
create table roles_entities(
partition_key text, row_key text,
value jsonb not null,
version integer not null,
etag uuid default public.gen_random_uuid());
raise log 'TIMING start roles_entities primary key';
alter table roles_entities add primary key (partition_key, row_key);
raise log 'TIMING start roles_entities insert';
perform 1 from roles;
if found then
insert into roles_entities
select
'role' as partition_key,
'role' as row_key,
entity_buf_encode(
jsonb_build_object(
'PartitionKey', 'roles',
'RowKey', 'roles'),
'blob', jsonb_agg(
jsonb_build_object(
'roleId', role_id,
'scopes', scopes,
'created', to_js_iso8601(created::text),
'description', description,
'lastModified', to_js_iso8601(last_modified::text))
)::text) as value,
1 as version,
-- use an aggregate function to select the etag (all rows have the same etag)
min(etag::text)::uuid as etag
from roles;
end if;
raise log 'TIMING start roles_entities permissions';
revoke select, insert, update, delete on roles from $db_user_prefix$_auth;
drop table roles;
grant select, insert, update, delete on roles_entities to $db_user_prefix$_auth;
drop function to_js_iso8601(ts_in text);
end