-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy path002_create_schema_postgres.sql
274 lines (208 loc) · 7.72 KB
/
002_create_schema_postgres.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
/*
NOTE: This file is to be used to populate the "geostore" and the "geostore_test" schemas
For example in Windows:
To populate the "geostore" schema with the "geostore" user:
set PGOPTIONS="--search_path=geostore"
psql -U geostore -d geostore -f 002_create_schema_postgres.sql
To populate the "geostore_test" schema with the "geostore_test" user:
set PGOPTIONS="--search_path=geostore_test"
psql -U geostore_test -d geostore -f 002_create_schema_postgres.sql
*/
SET search_path TO geostore;
create table gs_attribute (
id int8 not null,
attribute_date timestamp,
name varchar(255) not null,
attribute_number float8,
attribute_text varchar(255),
attribute_type varchar(255) not null,
resource_id int8 not null,
primary key (id),
unique (name, resource_id)
);
create table gs_category (
id int8 not null,
name varchar(255) not null,
primary key (id),
unique (name)
);
create table gs_resource (
id int8 not null,
creation timestamp not null,
description varchar(10000),
lastUpdate timestamp,
metadata varchar(30000),
name varchar(255) not null,
category_id int8 not null,
creator varchar(255),
editor varchar(255),
advertised bool not null default true,
primary key (id),
unique (name)
);
create table gs_security (
id int8 not null,
canRead bool not null,
canWrite bool not null,
group_id int8,
resource_id int8,
user_id int8,
username varchar(255),
groupname varchar(255),
primary key (id),
unique (user_id, resource_id),
unique (resource_id, group_id)
);
create table gs_stored_data (
id int8 not null,
stored_data varchar(10000000) not null,
resource_id int8 not null,
primary key (id),
unique (resource_id)
);
create table gs_user (
id int8 not null,
name varchar(255) not null,
user_password varchar(255),
user_role varchar(255) not null,
group_id int8,
enabled char(1) NOT NULL DEFAULT 'Y',
primary key (id),
unique (name)
);
create table gs_user_attribute (
id int8 not null,
name varchar(255) not null,
string varchar(255),
user_id int8 not null,
primary key (id),
unique (name, user_id)
);
create table gs_usergroup (
id int8 not null,
groupName varchar(255) not null,
description varchar(255),
enabled char(1) NOT NULL DEFAULT 'Y',
primary key (id),
unique (groupName)
);
create table gs_user_group_attribute (
id bigint not null,
name varchar(255) not null,
string varchar(255),
userGroup_id bigint not null,
primary key (id)
);
create table gs_usergroup_members (
user_id int8 not null,
group_id int8 not null,
primary key (user_id, group_id)
);
alter table gs_usergroup_members
add constraint FKFDE460DB62224F72
foreign key (user_id)
references gs_user;
alter table gs_usergroup_members
add constraint FKFDE460DB9EC981B7
foreign key (group_id)
references gs_usergroup;
create table gs_tag (
id int8 not null,
color varchar(255) not null,
description varchar(255) null,
"name" varchar(255) not null,
constraint gs_tag_pkey primary key (id)
);
create table gs_resource_tags (
tag_id int8 not null,
resource_id int8 not null,
constraint gs_resource_tags_pkey primary key (tag_id, resource_id)
);
alter table gs_resource_tags
add constraint fk_resource_tags_resource
foreign key (resource_id)
references gs_resource(id)
on delete cascade;
alter table gs_resource_tags
add constraint fk_resource_tags_tag
foreign key (tag_id)
references gs_tag(id);
create table gs_user_favorites (
user_id int8 not null,
resource_id int8 not null,
constraint gs_user_favorites_pkey primary key (user_id, resource_id)
);
alter table gs_user_favorites
add constraint fk_user_favorites_resource
foreign key (resource_id)
references gs_resource(id)
on delete cascade;
alter table gs_user_favorites
add constraint fk_user_favorites_user
foreign key (user_id)
references gs_user(id);
create index idx_attribute_name on gs_attribute (name);
create index idx_attribute_resource on gs_attribute (resource_id);
create index idx_attribute_text on gs_attribute (attribute_text);
create index idx_attribute_type on gs_attribute (attribute_type);
create index idx_attribute_date on gs_attribute (attribute_date);
create index idx_attribute_number on gs_attribute (attribute_number);
alter table gs_attribute
add constraint fk_attribute_resource
foreign key (resource_id)
references gs_resource;
create index idx_user_group_attr_name on gs_user_group_attribute (name);
create index idx_user_group_attr_text on gs_user_group_attribute (string);
create index idx_attr_user_group on gs_user_group_attribute (userGroup_id);
alter table gs_user_group_attribute add constraint fk_ugattrib_user_group foreign key (userGroup_id) references gs_usergroup;
create index idx_category_type on gs_category (name);
create index idx_resource_name on gs_resource (name);
create index idx_resource_description on gs_resource (description);
create index idx_resource_metadata on gs_resource (metadata);
create index idx_resource_update on gs_resource (lastUpdate);
create index idx_resource_creation on gs_resource (creation);
create index idx_resource_category on gs_resource (category_id);
alter table gs_resource
add constraint fk_resource_category
foreign key (category_id)
references gs_category;
create index idx_security_resource on gs_security (resource_id);
create index idx_security_user on gs_security (user_id);
create index idx_security_group on gs_security (group_id);
create index idx_security_write on gs_security (canWrite);
create index idx_security_read on gs_security (canRead);
create index idx_security_username on gs_security (username);
create index idx_security_groupname on gs_security (groupname);
alter table gs_security
add constraint fk_security_user
foreign key (user_id)
references gs_user;
alter table gs_security
add constraint fk_security_group
foreign key (group_id)
references gs_usergroup;
alter table gs_security
add constraint fk_security_resource
foreign key (resource_id)
references gs_resource;
alter table gs_stored_data
add constraint fk_data_resource
foreign key (resource_id)
references gs_resource;
create index idx_user_group on gs_user (group_id);
create index idx_user_password on gs_user (user_password);
create index idx_user_name on gs_user (name);
create index idx_user_role on gs_user (user_role);
alter table gs_user
add constraint fk_user_ugroup
foreign key (group_id)
references gs_usergroup;
create index idx_user_attribute_name on gs_user_attribute (name);
create index idx_user_attribute_text on gs_user_attribute (string);
create index idx_attribute_user on gs_user_attribute (user_id);
alter table gs_user_attribute
add constraint fk_uattrib_user
foreign key (user_id)
references gs_user;
create index idx_usergroup_name on gs_usergroup (groupName);
create sequence hibernate_sequence;