-
Notifications
You must be signed in to change notification settings - Fork 1
/
Orcid_Schema_Mysql.sql
172 lines (160 loc) · 4.53 KB
/
Orcid_Schema_Mysql.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
create database ULS;
create table ULS.orcid_users
( id bigint not null auto_increment,
username varchar(8) not null,
orcid varchar(19),
token varchar(255),
created date,
modified date,
primary key (id)
);
create table ULS.orcid_status_types
( id bigint not null auto_increment,
name varchar(512) not null,
seq numeric(38,0),
primary key (id)
);
create table ULS.orcid_batch_creators
( id bigint not null auto_increment,
name varchar(8) not null,
flags bigint default 0 not null,
primary key (id)
);
create table ULS.orcid_batch_groups
( id bigint not null auto_increment,
name varchar(512) not null,
group_definition varchar(2048),
employee_definition varchar(2048),
student_definition varchar(2048),
cache_creation_date date,
primary key (id)
);
create table ULS.orcid_batches
( id bigint not null auto_increment,
name varchar(512) not null,
subject varchar(512) not null,
body longtext not null,
from_name varchar(64) not null,
from_addr varchar(64) not null,
reply_to varchar(64),
orcid_batch_creator_id bigint not null,
primary key (id),
foreign key (orcid_batch_creator_id) references orcid_batch_creators(id)
);
create table ULS.orcid_batch_group_caches
( id bigint not null auto_increment,
orcid_batch_group_id bigint not null,
orcid_user_id bigint not null,
deprecated date,
primary key (id),
foreign key (orcid_batch_group_id) references orcid_batch_groups(id),
foreign key (orcid_user_id) references orcid_users(id)
);
create table ULS.orcid_batch_triggers
( id bigint not null auto_increment,
name varchar(512) not null,
orcid_status_type_id bigint not null,
orcid_batch_id bigint not null,
trigger_delay numeric(38,0) not null,
orcid_batch_group_id bigint,
begin_date date,
repeat_value numeric(38,0) default 0 not null,
maximum_repeat numeric(38,0) default 0 not null,
primary key (id),
foreign key (orcid_batch_id) references orcid_batches(id),
foreign key (orcid_status_type_id) references orcid_status_types(id),
foreign key (orcid_batch_group_id) references orcid_batch_groups(id)
);
create table ULS.orcid_emails
( id bigint not null auto_increment,
orcid_user_id bigint not null,
orcid_batch_id bigint not null,
queued date,
sent date,
cancelled date,
primary key (id),
foreign key (orcid_user_id) references orcid_users(id),
foreign key (orcid_batch_id) references orcid_batches(id)
);
create table ULS.orcid_statuses
( id bigint not null auto_increment,
orcid_user_id bigint not null,
orcid_status_type_id bigint not null,
status_timestamp date not null,
primary key (id),
foreign key (orcid_user_id) references orcid_users(id),
foreign key (orcid_status_type_id) references orcid_status_types(id)
);
CREATE VIEW AS all_orcid_statuses
select
orcid_statuses.orcid_user_id,
orcid_statuses.orcid_status_type_id,
orcid_statuses.status_timestamp
from
orcid_statuses
union
select
orcid_users.id orcid_user_id,
orcid_status_types.id orcid_status_type_id,
orcid_users.created status_timestamp
from
orcid_users
join orcid_status_types on (orcid_status_types.seq = 0)
union
select
orcid_emails.orcid_user_id,
orcid_status_types.id orcid_status_type_id,
min(orcid_emails.sent) status_timestamp
from
orcid_emails
join orcid_status_types on (orcid_status_types.seq = 1)
where
sent is not null
group by
orcid_emails.orcid_user_id,
orcid_status_types.id
union
select
orcid_users.id orcid_user_id,
orcid_status_types.id orcid_status_type_id,
orcid_users.modified status_timestamp
from
orcid_users
join orcid_status_types on (
orcid_users.orcid is not null
and orcid_status_types.seq = 3
)
union
select
orcid_users.id orcid_user_id,
orcid_status_types.id orcid_status_type_id,
orcid_users.modified status_timestamp
from
orcid_users
join orcid_status_types on (
orcid_users.orcid is not null
and orcid_users.token is not null
and orcid_status_types.seq = 4
)
create view current_orcid_status as(
select
all_orcid_statuses.orcid_user_id,
all_orcid_statuses.orcid_status_type_id,
all_orcid_statuses.status_timestamp
from
all_orcid_statuses
join orcid_status_types on (
all_orcid_statuses.orcid_status_type_id = orcid_status_types.id
)
where
orcid_user_id not in (
select
s.orcid_user_id
from
all_orcid_statuses s
join orcid_status_types t on (s.orcid_status_type_id = t.id)
where
s.orcid_user_id = all_orcid_statuses.orcid_user_id
and t.seq > orcid_status_types.seq
)
)