forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0020-downgrade.sql
121 lines (109 loc) · 4.62 KB
/
0020-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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
begin
-- lock this table before reading from it, to prevent loss of concurrent
-- updates when the table is dropped.
lock table tasks;
raise log 'TIMING start queue_tasks_entities create table';
create table queue_tasks_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 queue_tasks_entities primary key';
alter table queue_tasks_entities add primary key (partition_key, row_key);
raise log 'TIMING start queue_task_group_members_entities create table';
create table queue_task_group_members_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 queue_task_group_members_entities primary key';
alter table queue_task_group_members_entities add primary key (partition_key, row_key);
raise log 'TIMING start queue_task_group_active_sets_entities create table';
create table queue_task_group_active_sets_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 queue_task_group_active_sets_entities primary key';
alter table queue_task_group_active_sets_entities add primary key (partition_key, row_key);
raise log 'TIMING start queue_tasks_entities insert';
insert into queue_tasks_entities
select
-- note, the partition_key is the slugid form, not uuid, and contains no
-- characters that must be escaped in an Azure key
task_id as partition_key,
'task' as row_key,
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
jsonb_build_object(
'PartitionKey', task_id,
'RowKey', 'task',
'taskId', slugid_to_uuid(task_id),
'provisionerId', provisioner_id,
'workerType', worker_type,
'schedulerId', scheduler_id,
'taskGroupId', slugid_to_uuid(task_group_id),
'requires', requires::text,
'priority', priority::text,
'retries', retries,
'retriesLeft', retries_left,
'created', created,
'deadline', deadline,
'expires', expires,
'takenUntil', coalesce(taken_until, '1970-01-01 00:00:00+00'::timestamptz)),
'dependencies', dependencies::text),
'routes', routes::text),
'scopes', scopes::text),
'payload', payload::text),
'metadata', metadata::text),
'tags', tags::text),
'extra', extra::text),
'runs', runs::text) as value,
1 as version,
etag
from tasks;
-- queue_task_group_members_entities is just a different index on the tasks
-- table, so we reconstruct it from the tasks
raise log 'TIMING start queue_task_group_members_entities insert';
insert into queue_task_group_members_entities
select
task_group_id as partition_key,
task_id as row_key,
jsonb_build_object(
'PartitionKey', task_group_id,
'RowKey', task_id,
'taskId', slugid_to_uuid(task_id),
'taskGroupId', slugid_to_uuid(task_group_id)) as value,
1 as version,
etag
from tasks;
-- similarly for queue_task_group_active_sets_entities
raise log 'TIMING start queue_task_group_active_sets_entities insert';
insert into queue_task_group_active_sets_entities
select
task_group_id as partition_key,
task_id as row_key,
jsonb_build_object(
'PartitionKey', task_group_id,
'RowKey', task_id,
'taskId', slugid_to_uuid(task_id),
'taskGroupId', slugid_to_uuid(task_group_id)) as value,
1 as version,
etag
from tasks
where not ever_resolved;
raise log 'TIMING start queue_{tasks,task_group_{active_sets.members}_entities} permissions';
revoke select, insert, update, delete on tasks from $db_user_prefix$_queue;
drop table tasks;
grant select, insert, update, delete on queue_tasks_entities to $db_user_prefix$_queue;
grant select, insert, update, delete on queue_task_group_members_entities to $db_user_prefix$_queue;
grant select, insert, update, delete on queue_task_group_active_sets_entities to $db_user_prefix$_queue;
drop type task_requires;
drop type task_priority;
end