-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy path1.sql
297 lines (210 loc) · 11 KB
/
1.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions
# --- !Ups
create table client (
id bigint not null,
name varchar(255),
client_id varchar(255),
secret varchar(255),
redirect varchar(255),
user_id bigint,
linked boolean,
constraint pk_client primary key (id))
;
create table data_source (
id bigint not null,
value varchar(255),
is_public boolean,
constraint pk_data_source primary key (id))
;
create table groups (
id bigint not null,
name varchar(255),
description varchar(255),
constraint pk_groups primary key (id))
;
create table group_data_source_read (
id bigint not null,
group_id bigint,
data_source_id bigint,
constraint pk_group_data_source_read primary key (id),
constraint uq_group_data_source_read unique (group_id, data_source_id))
;
create table group_data_source_write (
id bigint not null,
group_id bigint,
data_source_id bigint,
constraint pk_group_data_source_write primary key (id),
constraint uq_group_data_source_write unique (group_id, data_source_id))
;
create table linked_account (
id bigint not null,
user_id bigint,
provider_user_id varchar(255),
provider_key varchar(255),
constraint pk_linked_account primary key (id))
;
create table oauth_code (
id bigint not null,
user_id bigint,
client_id bigint,
code varchar(255),
creation bigint,
constraint pk_oauth_code primary key (id))
;
create table oauth_token (
id bigint not null,
user_id bigint,
client_id bigint,
token varchar(255),
refresh varchar(255),
creation bigint,
duration bigint,
constraint pk_oauth_token primary key (id))
;
create table security_role (
id bigint not null,
role_name varchar(255),
constraint pk_security_role primary key (id))
;
create table token_action (
id bigint not null,
token varchar(255),
target_user_id bigint,
type varchar(2),
created timestamp,
expires timestamp,
constraint ck_token_action_type check (type in ('PR','EV')),
constraint uq_token_action_token unique (token),
constraint pk_token_action primary key (id))
;
create table users (
id bigint not null,
email varchar(255),
name varchar(255),
first_name varchar(255),
last_name varchar(255),
last_login timestamp,
active boolean,
email_validated boolean,
constraint uq_users_email unique (email),
constraint pk_users primary key (id))
;
create table user_data_source_read (
id bigint not null,
user_id bigint,
data_source_id bigint,
constraint pk_user_data_source_read primary key (id),
constraint uq_user_data_source_read unique (user_id, data_source_id))
;
create table user_data_source_write (
id bigint not null,
user_id bigint,
data_source_id bigint,
constraint pk_user_data_source_write primary key (id),
constraint uq_user_data_source_write unique (user_id, data_source_id))
;
create table user_permission (
id bigint not null,
value varchar(255),
constraint pk_user_permission primary key (id))
;
create table users_security_role (
users_id bigint not null,
security_role_id bigint not null,
constraint pk_users_security_role primary key (users_id, security_role_id))
;
create table users_user_permission (
users_id bigint not null,
user_permission_id bigint not null,
constraint pk_users_user_permission primary key (users_id, user_permission_id))
;
create table client_users (
users_id bigint not null,
client_id bigint not null,
constraint pk_client_users primary key (users_id, client_id))
;
create table users_groups (
users_id bigint not null,
groups_id bigint not null,
constraint pk_users_groups primary key (users_id, groups_id))
;
create sequence client_seq;
create sequence data_source_seq;
create sequence groups_seq;
create sequence group_data_source_read_seq;
create sequence group_data_source_write_seq;
create sequence linked_account_seq;
create sequence oauth_code_seq;
create sequence oauth_token_seq;
create sequence security_role_seq;
create sequence token_action_seq;
create sequence users_seq;
create sequence user_data_source_read_seq;
create sequence user_data_source_write_seq;
create sequence user_permission_seq;
alter table client add constraint fk_client_user_1 foreign key (user_id) references users (id) on delete restrict on update restrict;
create index ix_client_user_1 on client (user_id);
alter table linked_account add constraint fk_linked_account_user_2 foreign key (user_id) references users (id) on delete restrict on update restrict;
create index ix_linked_account_user_2 on linked_account (user_id);
alter table oauth_code add constraint fk_oauth_code_user_3 foreign key (user_id) references users (id) on delete restrict on update restrict;
create index ix_oauth_code_user_3 on oauth_code (user_id);
alter table oauth_code add constraint fk_oauth_code_client_4 foreign key (client_id) references client (id) on delete restrict on update restrict;
create index ix_oauth_code_client_4 on oauth_code (client_id);
alter table oauth_token add constraint fk_oauth_token_user_5 foreign key (user_id) references users (id) on delete restrict on update restrict;
create index ix_oauth_token_user_5 on oauth_token (user_id);
alter table oauth_token add constraint fk_oauth_token_client_6 foreign key (client_id) references client (id) on delete restrict on update restrict;
create index ix_oauth_token_client_6 on oauth_token (client_id);
alter table token_action add constraint fk_token_action_targetUser_7 foreign key (target_user_id) references users (id) on delete restrict on update restrict;
create index ix_token_action_targetUser_7 on token_action (target_user_id);
alter table group_data_source_read add constraint fk_group_data_source_read_groups_01 foreign key (group_id) references groups (id) on delete restrict on update restrict;
alter table group_data_source_read add constraint fk_group_data_source_read_data_02 foreign key (data_source_id) references data_source (id) on delete restrict on update restrict;
alter table group_data_source_write add constraint fk_group_data_source_write_groups_01 foreign key (group_id) references groups (id) on delete restrict on update restrict;
alter table group_data_source_write add constraint fk_group_data_source_write_data_02 foreign key (data_source_id) references data_source (id) on delete restrict on update restrict;
alter table users_security_role add constraint fk_users_security_role_users_01 foreign key (users_id) references users (id) on delete restrict on update restrict;
alter table users_security_role add constraint fk_users_security_role_securi_02 foreign key (security_role_id) references security_role (id) on delete restrict on update restrict;
alter table users_user_permission add constraint fk_users_user_permission_user_01 foreign key (users_id) references users (id) on delete restrict on update restrict;
alter table users_user_permission add constraint fk_users_user_permission_user_02 foreign key (user_permission_id) references user_permission (id) on delete restrict on update restrict;
alter table user_data_source_read add constraint fk_user_data_source_read_users_01 foreign key (user_id) references users (id) on delete restrict on update restrict;
alter table user_data_source_read add constraint fk_user_data_source_read_data_02 foreign key (data_source_id) references data_source (id) on delete restrict on update restrict;
alter table user_data_source_write add constraint fk_user_data_source_write_users_01 foreign key (user_id) references users (id) on delete restrict on update restrict;
alter table user_data_source_write add constraint fk_user_data_source_write_data_02 foreign key (data_source_id) references data_source (id) on delete restrict on update restrict;
alter table client_users add constraint fk_client_users_users_01 foreign key (users_id) references users (id) on delete restrict on update restrict;
alter table client_users add constraint fk_client_users_client_02 foreign key (client_id) references client (id) on delete restrict on update restrict;
alter table users_groups add constraint fk_users_groups_users_01 foreign key (users_id) references users (id) on delete restrict on update restrict;
alter table users_groups add constraint fk_users_groups_groups_02 foreign key (groups_id) references groups (id) on delete restrict on update restrict;
# --- !Downs
SET REFERENTIAL_INTEGRITY FALSE;
drop table if exists client;
drop table if exists data_source;
drop table if exists group_data_source_read;
drop table if exists user_data_source_read;
drop table if exists group_data_source_write;
drop table if exists user_data_source_write;
drop table if exists groups;
drop table if exists users_groups;
drop table if exists linked_account;
drop table if exists oauth_code;
drop table if exists oauth_token;
drop table if exists security_role;
drop table if exists token_action;
drop table if exists users;
drop table if exists client_users;
drop table if exists users_security_role;
drop table if exists users_user_permission;
drop table if exists user_permission;
SET REFERENTIAL_INTEGRITY TRUE;
drop sequence if exists client_seq;
drop sequence if exists data_source_seq;
drop sequence if exists groups_seq;
drop sequence if exists group_data_source_read_seq;
drop sequence if exists group_data_source_write_seq;
drop sequence if exists linked_account_seq;
drop sequence if exists oauth_code_seq;
drop sequence if exists oauth_token_seq;
drop sequence if exists security_role_seq;
drop sequence if exists token_action_seq;
drop sequence if exists users_seq;
drop sequence if exists user_data_source_read_seq;
drop sequence if exists user_data_source_write_seq;
drop sequence if exists user_permission_seq;