1
|
-- Existing tables
|
2
|
|
3
|
CREATE TABLE aux_role
|
4
|
(
|
5
|
role_id serial NOT NULL,
|
6
|
rolecode character varying(30) NOT NULL,
|
7
|
roledescription character varying(200),
|
8
|
CONSTRAINT aux_role_pkey PRIMARY KEY (role_id )
|
9
|
);
|
10
|
|
11
|
CREATE TABLE reference
|
12
|
(
|
13
|
reference_id serial NOT NULL,
|
14
|
shortname character varying(250),
|
15
|
fulltext text,
|
16
|
referencetype character varying(250)
|
17
|
);
|
18
|
|
19
|
CREATE TABLE party
|
20
|
(
|
21
|
party_id serial NOT NULL,
|
22
|
salutation character varying(20),
|
23
|
givenname character varying(50),
|
24
|
middlename character varying(50),
|
25
|
surname character varying(50),
|
26
|
organizationname character varying(100)
|
27
|
);
|
28
|
|
29
|
CREATE TABLE plantname
|
30
|
(
|
31
|
plantname_id serial NOT NULL,
|
32
|
plantname character varying(255) NOT NULL,
|
33
|
reference_id integer,
|
34
|
dateentered timestamp with time zone DEFAULT now(),
|
35
|
CONSTRAINT plantname_pkey PRIMARY KEY (plantname_id ),
|
36
|
CONSTRAINT plantname_reference_id FOREIGN KEY (reference_id)
|
37
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
38
|
ON UPDATE CASCADE ON DELETE CASCADE
|
39
|
);
|
40
|
|
41
|
CREATE TABLE plantconcept
|
42
|
(
|
43
|
plantconcept_id serial NOT NULL,
|
44
|
plantname_id integer NOT NULL,
|
45
|
reference_id integer NOT NULL,
|
46
|
plantname character varying(200),
|
47
|
plantcode character varying(23),
|
48
|
plantdescription text,
|
49
|
d_obscount integer,
|
50
|
d_currentaccepted boolean,
|
51
|
accessioncode character varying(255),
|
52
|
CONSTRAINT plantconcept_pkey PRIMARY KEY (plantconcept_id ),
|
53
|
CONSTRAINT plantconcept_plantname_id FOREIGN KEY (plantname_id)
|
54
|
REFERENCES plantname (plantname_id) MATCH SIMPLE
|
55
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
56
|
CONSTRAINT plantconcept_reference_id FOREIGN KEY (reference_id)
|
57
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
58
|
ON UPDATE CASCADE ON DELETE CASCADE
|
59
|
);
|
60
|
|
61
|
CREATE TABLE stratummethod
|
62
|
(
|
63
|
stratummethod_id serial NOT NULL,
|
64
|
reference_id integer,
|
65
|
stratummethodname character varying(30) NOT NULL,
|
66
|
stratummethoddescription text,
|
67
|
stratumassignment character varying(50),
|
68
|
accessioncode character varying(255),
|
69
|
CONSTRAINT stratummethod_pkey PRIMARY KEY (stratummethod_id ),
|
70
|
CONSTRAINT stratummethod_reference_id FOREIGN KEY (reference_id)
|
71
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
72
|
ON UPDATE CASCADE ON DELETE CASCADE
|
73
|
);
|
74
|
|
75
|
CREATE TABLE stratumtype
|
76
|
(
|
77
|
stratumtype_id serial NOT NULL,
|
78
|
stratummethod_id integer NOT NULL,
|
79
|
stratumindex character varying(10),
|
80
|
stratumname character varying(30),
|
81
|
stratumdescription text,
|
82
|
CONSTRAINT stratumtype_pkey PRIMARY KEY (stratumtype_id ),
|
83
|
CONSTRAINT stratumtype_stratummethod_id FOREIGN KEY (stratummethod_id)
|
84
|
REFERENCES stratummethod (stratummethod_id) MATCH SIMPLE
|
85
|
ON UPDATE CASCADE ON DELETE CASCADE
|
86
|
);
|
87
|
|
88
|
CREATE TABLE namedplace
|
89
|
(
|
90
|
namedplace_id serial NOT NULL,
|
91
|
placesystem character varying(50),
|
92
|
placename character varying(100) NOT NULL,
|
93
|
placedescription text,
|
94
|
placecode character varying(15),
|
95
|
owner character varying(100),
|
96
|
reference_id integer,
|
97
|
d_obscount integer,
|
98
|
accessioncode character varying(255),
|
99
|
CONSTRAINT namedplace_pkey PRIMARY KEY (namedplace_id ),
|
100
|
CONSTRAINT namedplace_reference_id FOREIGN KEY (reference_id)
|
101
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
102
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
103
|
CONSTRAINT namedplace_keys UNIQUE (placesystem , placename )
|
104
|
);
|
105
|
|
106
|
CREATE TABLE locationplace
|
107
|
(
|
108
|
locationplace_id serial NOT NULL,
|
109
|
location_id integer NOT NULL,
|
110
|
calculated boolean,
|
111
|
namedplace_id integer NOT NULL,
|
112
|
CONSTRAINT locationplace_pkey PRIMARY KEY (locationplace_id ),
|
113
|
CONSTRAINT locationplace_location_id FOREIGN KEY (location_id)
|
114
|
REFERENCES location (location_id) MATCH SIMPLE
|
115
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
116
|
CONSTRAINT locationplace_namedplace_id FOREIGN KEY (namedplace_id)
|
117
|
REFERENCES namedplace (namedplace_id) MATCH SIMPLE
|
118
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
119
|
CONSTRAINT locationplace_keys UNIQUE (location_id , namedplace_id )
|
120
|
);
|
121
|
|
122
|
CREATE TABLE project
|
123
|
(
|
124
|
project_id serial NOT NULL,
|
125
|
projectname character varying(150) NOT NULL,
|
126
|
projectdescription text,
|
127
|
startdate timestamp with time zone,
|
128
|
stopdate timestamp with time zone,
|
129
|
d_obscount integer,
|
130
|
d_lastlocationaddeddate timestamp with time zone,
|
131
|
accessioncode character varying(255),
|
132
|
CONSTRAINT project_pkey PRIMARY KEY (project_id ),
|
133
|
CONSTRAINT project_keys UNIQUE (projectname , startdate , stopdate )
|
134
|
);
|
135
|
|
136
|
-- New tables
|
137
|
|
138
|
CREATE TABLE location
|
139
|
(
|
140
|
location_id serial NOT NULL,
|
141
|
authorlocationcode character varying(30),
|
142
|
reference_id integer,
|
143
|
parent_id integer,
|
144
|
reallatitude double precision,
|
145
|
reallongitude double precision,
|
146
|
locationaccuracy double precision,
|
147
|
confidentialitystatus integer NOT NULL DEFAULT 0,
|
148
|
confidentialityreason character varying(200),
|
149
|
publiclatitude double precision,
|
150
|
publiclongitude double precision,
|
151
|
"... (truncated) ..." integer,
|
152
|
accessioncode character varying(255),
|
153
|
sublocationxposition double precision,
|
154
|
sublocationyposition double precision,
|
155
|
namedplace_id integer,
|
156
|
CONSTRAINT location_pkey PRIMARY KEY (location_id ),
|
157
|
CONSTRAINT location_namedplace_id FOREIGN KEY (namedplace_id)
|
158
|
REFERENCES namedplace (namedplace_id) MATCH SIMPLE
|
159
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
160
|
CONSTRAINT location_parent_id FOREIGN KEY (parent_id)
|
161
|
REFERENCES location (location_id) MATCH SIMPLE
|
162
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
163
|
CONSTRAINT location_reference_id FOREIGN KEY (reference_id)
|
164
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
165
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
166
|
CONSTRAINT location_keys_code UNIQUE (reference_id , authorlocationcode ),
|
167
|
CONSTRAINT location_keys_coords UNIQUE (reference_id , reallatitude , reallongitude ),
|
168
|
CONSTRAINT location_keys_subplot_code UNIQUE (parent_id , authorlocationcode ),
|
169
|
CONSTRAINT location_keys_subplot_coords UNIQUE (parent_id , sublocationxposition , sublocationyposition )
|
170
|
);
|
171
|
|
172
|
CREATE TABLE locationevent -- VegBank's observation table.
|
173
|
(
|
174
|
locationevent_id serial NOT NULL,
|
175
|
previous_id integer,
|
176
|
location_id integer NOT NULL,
|
177
|
project_id integer,
|
178
|
authoreventcode character varying(30),
|
179
|
"... (truncated) ..." integer,
|
180
|
accessioncode character varying(255),
|
181
|
sourceaccessioncode character varying(100),
|
182
|
CONSTRAINT locationevent_pkey PRIMARY KEY (locationevent_id ),
|
183
|
CONSTRAINT locationevent_location_id FOREIGN KEY (location_id)
|
184
|
REFERENCES location (location_id) MATCH SIMPLE
|
185
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
186
|
CONSTRAINT locationevent_project_id FOREIGN KEY (project_id)
|
187
|
REFERENCES project (project_id) MATCH SIMPLE
|
188
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
189
|
CONSTRAINT locationevent_keys_accessioncode UNIQUE (location_id , project_id , sourceaccessioncode ),
|
190
|
CONSTRAINT locationevent_keys_code UNIQUE (location_id , project_id , authoreventcode )
|
191
|
);
|
192
|
|
193
|
CREATE TABLE taxonoccurrence -- VegBank's taxonobservation table.
|
194
|
(
|
195
|
taxonoccurrence_id serial NOT NULL,
|
196
|
locationevent_id integer NOT NULL,
|
197
|
authorplantname character varying(255),
|
198
|
reference_id integer,
|
199
|
taxoninferencearea double precision,
|
200
|
emb_taxonoccurrence integer,
|
201
|
"... (truncated) ..." integer,
|
202
|
accessioncode character varying(255),
|
203
|
CONSTRAINT taxonoccurrence_pkey PRIMARY KEY (taxonoccurrence_id ),
|
204
|
CONSTRAINT taxonoccurrence_locationevent_id FOREIGN KEY (locationevent_id)
|
205
|
REFERENCES locationevent (locationevent_id) MATCH SIMPLE
|
206
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
207
|
CONSTRAINT taxonoccurrence_reference_id FOREIGN KEY (reference_id)
|
208
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
209
|
ON UPDATE CASCADE ON DELETE CASCADE
|
210
|
);
|
211
|
|
212
|
CREATE TABLE aggregateoccurrence -- VegBank's taxonimportance table.
|
213
|
(
|
214
|
aggregateoccurrence_id serial NOT NULL,
|
215
|
taxonoccurrence_id integer NOT NULL,
|
216
|
taxonbinmethod_id integer,
|
217
|
cover double precision,
|
218
|
basalarea double precision,
|
219
|
biomass double precision,
|
220
|
inferencearea double precision,
|
221
|
stratumbase double precision,
|
222
|
stratumheight double precision,
|
223
|
emb_aggregateoccurrence integer,
|
224
|
covercode character varying(10),
|
225
|
count integer NOT NULL,
|
226
|
accessioncode character varying(255),
|
227
|
sourceaccessioncode character varying(100),
|
228
|
CONSTRAINT aggregateoccurrence_pkey PRIMARY KEY (aggregateoccurrence_id ),
|
229
|
CONSTRAINT aggregateoccurrence_taxonbinmethod_id FOREIGN KEY (taxonbinmethod_id)
|
230
|
REFERENCES taxonbinmethod (taxonbinmethod_id) MATCH SIMPLE
|
231
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
232
|
CONSTRAINT aggregateoccurrence_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
|
233
|
REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
|
234
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
235
|
CONSTRAINT aggregateoccurrence_keys_accessioncode UNIQUE (taxonoccurrence_id , sourceaccessioncode ),
|
236
|
CONSTRAINT aggregateoccurrence_keys_method UNIQUE (taxonoccurrence_id , taxonbinmethod_id )
|
237
|
);
|
238
|
|
239
|
CREATE TABLE individualplant -- VegBank's stemcount table.
|
240
|
(
|
241
|
individualplant_id serial NOT NULL,
|
242
|
aggregateoccurrence_id integer NOT NULL,
|
243
|
overallheight double precision,
|
244
|
overallheightaccuracy double precision,
|
245
|
emb_individualplant integer,
|
246
|
authorplantcode character varying(20),
|
247
|
accessioncode character varying(255),
|
248
|
stemcount integer,
|
249
|
sourceaccessioncode character varying(100),
|
250
|
CONSTRAINT individualplant_pkey PRIMARY KEY (individualplant_id ),
|
251
|
CONSTRAINT individualplant_aggregateoccurrence_id FOREIGN KEY (aggregateoccurrence_id)
|
252
|
REFERENCES aggregateoccurrence (aggregateoccurrence_id) MATCH SIMPLE
|
253
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
254
|
CONSTRAINT individualplant_keys_accessioncode UNIQUE (aggregateoccurrence_id , sourceaccessioncode ),
|
255
|
CONSTRAINT individualplant_keys_code UNIQUE (aggregateoccurrence_id , authorplantcode )
|
256
|
);
|
257
|
|
258
|
CREATE TABLE stem -- VegBank's stemlocation table.
|
259
|
(
|
260
|
stem_id serial NOT NULL,
|
261
|
individualplant_id integer NOT NULL,
|
262
|
authorstemcode character varying(20),
|
263
|
xposition double precision,
|
264
|
yposition double precision,
|
265
|
health character varying(50),
|
266
|
emb_stem integer,
|
267
|
diameter double precision,
|
268
|
height double precision,
|
269
|
heightaccuracy double precision,
|
270
|
age double precision,
|
271
|
accessioncode character varying(255),
|
272
|
diameteraccuracy double precision,
|
273
|
sourceaccessioncode character varying(100),
|
274
|
CONSTRAINT stem_pkey PRIMARY KEY (stem_id ),
|
275
|
CONSTRAINT stem_individualplant_id FOREIGN KEY (individualplant_id)
|
276
|
REFERENCES individualplant (individualplant_id) MATCH SIMPLE
|
277
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
278
|
CONSTRAINT stem_keys_accessioncode UNIQUE (individualplant_id , sourceaccessioncode ),
|
279
|
CONSTRAINT stem_keys_code UNIQUE (individualplant_id , authorstemcode )
|
280
|
);
|
281
|
|
282
|
CREATE TABLE specimen -- A herbarium specimen. Contains Darwin Core specimen data.
|
283
|
(
|
284
|
specimen_id serial NOT NULL,
|
285
|
reference_id integer NOT NULL,
|
286
|
collectioncode_dwc character varying(255),
|
287
|
catalognumber_dwc character varying(255),
|
288
|
collectiondate timestamp with time zone,
|
289
|
collector_id integer,
|
290
|
museum_id integer,
|
291
|
sourceaccessioncode character varying(100),
|
292
|
accessioncode character varying(255),
|
293
|
taxonoccurrence_id integer NOT NULL,
|
294
|
collectornumber_dwc character varying(255),
|
295
|
authorspecimencode character varying(20),
|
296
|
CONSTRAINT specimen_pkey PRIMARY KEY (specimen_id ),
|
297
|
CONSTRAINT specimen_collector_id FOREIGN KEY (collector_id)
|
298
|
REFERENCES party (party_id) MATCH SIMPLE
|
299
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
300
|
CONSTRAINT specimen_museum_id FOREIGN KEY (museum_id)
|
301
|
REFERENCES party (party_id) MATCH SIMPLE
|
302
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
303
|
CONSTRAINT specimen_reference_id_fkey FOREIGN KEY (reference_id)
|
304
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
305
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
306
|
CONSTRAINT specimen_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
|
307
|
REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
|
308
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
309
|
CONSTRAINT specimen_keys_accessioncode UNIQUE (reference_id , collectioncode_dwc , sourceaccessioncode ),
|
310
|
CONSTRAINT specimen_keys_catalognumber UNIQUE (reference_id , collectioncode_dwc , catalognumber_dwc ),
|
311
|
CONSTRAINT specimen_keys_code UNIQUE (reference_id , collectioncode_dwc , authorspecimencode )
|
312
|
);
|
313
|
|
314
|
CREATE TABLE voucher
|
315
|
(
|
316
|
voucher_id serial NOT NULL,
|
317
|
taxonoccurrence_id integer NOT NULL,
|
318
|
specimen_id integer NOT NULL,
|
319
|
accessioncode character varying(255),
|
320
|
CONSTRAINT voucher_pkey PRIMARY KEY (voucher_id ),
|
321
|
CONSTRAINT voucher_specimen_id FOREIGN KEY (specimen_id)
|
322
|
REFERENCES specimen (specimen_id) MATCH SIMPLE
|
323
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
324
|
CONSTRAINT voucher_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
|
325
|
REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
|
326
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
327
|
CONSTRAINT voucher_keys UNIQUE (taxonoccurrence_id , specimen_id )
|
328
|
);
|
329
|
|
330
|
CREATE TABLE taxondetermination -- VegBank's taxoninterpretation table.
|
331
|
(
|
332
|
taxondetermination_id serial NOT NULL,
|
333
|
taxonoccurrence_id integer NOT NULL,
|
334
|
plantconcept_id integer NOT NULL,
|
335
|
party_id integer,
|
336
|
role_id integer NOT NULL,
|
337
|
determinationtype character varying(30),
|
338
|
reference_id integer,
|
339
|
originaldetermination boolean NOT NULL DEFAULT false,
|
340
|
currentdetermination boolean NOT NULL DEFAULT false,
|
341
|
taxonfit character varying(50),
|
342
|
taxonconfidence character varying(50),
|
343
|
grouptype character varying(20),
|
344
|
notes text,
|
345
|
notespublic boolean,
|
346
|
notesmgt boolean,
|
347
|
revisions boolean,
|
348
|
determinationdate timestamp with time zone,
|
349
|
emb_taxondetermination integer,
|
350
|
accessioncode character varying(255),
|
351
|
CONSTRAINT taxondetermination_pkey PRIMARY KEY (taxondetermination_id ),
|
352
|
CONSTRAINT taxondetermination_party_id FOREIGN KEY (party_id)
|
353
|
REFERENCES party (party_id) MATCH SIMPLE
|
354
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
355
|
CONSTRAINT taxondetermination_plantconcept_id FOREIGN KEY (plantconcept_id)
|
356
|
REFERENCES plantconcept (plantconcept_id) MATCH SIMPLE
|
357
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
358
|
CONSTRAINT taxondetermination_reference_id FOREIGN KEY (reference_id)
|
359
|
REFERENCES reference (reference_id) MATCH SIMPLE
|
360
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
361
|
CONSTRAINT taxondetermination_role_id FOREIGN KEY (role_id)
|
362
|
REFERENCES aux_role (role_id) MATCH SIMPLE
|
363
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
364
|
CONSTRAINT taxondetermination_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
|
365
|
REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
|
366
|
ON UPDATE CASCADE ON DELETE CASCADE
|
367
|
);
|
368
|
|
369
|
CREATE TABLE stratum
|
370
|
(
|
371
|
stratum_id serial NOT NULL,
|
372
|
locationevent_id integer NOT NULL,
|
373
|
stratumtype_id integer NOT NULL,
|
374
|
stratummethod_id integer,
|
375
|
stratumname character varying(30),
|
376
|
stratumheight double precision,
|
377
|
stratumbase double precision,
|
378
|
stratumcover double precision,
|
379
|
stratumdescription character varying(200),
|
380
|
CONSTRAINT stratum_pkey PRIMARY KEY (stratum_id ),
|
381
|
CONSTRAINT stratum_locationevent_id FOREIGN KEY (locationevent_id)
|
382
|
REFERENCES locationevent (locationevent_id) MATCH SIMPLE
|
383
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
384
|
CONSTRAINT stratum_stratumtype_id FOREIGN KEY (stratumtype_id)
|
385
|
REFERENCES stratumtype (stratumtype_id) MATCH SIMPLE
|
386
|
ON UPDATE CASCADE ON DELETE CASCADE
|
387
|
);
|
388
|
|
389
|
CREATE TABLE sizeclass -- A range of size measurements used to aggregate organisms.
|
390
|
(
|
391
|
sizeclass_id serial NOT NULL,
|
392
|
mindiameter double precision,
|
393
|
minheight double precision,
|
394
|
maxdiameter double precision,
|
395
|
maxheight double precision,
|
396
|
accessioncode character varying(255),
|
397
|
CONSTRAINT sizeclass_pkey PRIMARY KEY (sizeclass_id )
|
398
|
);
|
399
|
|
400
|
CREATE TABLE taxonbinmethod
|
401
|
(
|
402
|
taxonbinmethod_id integer NOT NULL,
|
403
|
label character varying(255),
|
404
|
stratumtype_id integer,
|
405
|
sizeclass_id integer,
|
406
|
coverindex_id integer,
|
407
|
accessioncode character varying(255),
|
408
|
CONSTRAINT taxonbinmethod_pkey PRIMARY KEY (taxonbinmethod_id ),
|
409
|
CONSTRAINT taxonbinmethod_sizeclass_id FOREIGN KEY (sizeclass_id)
|
410
|
REFERENCES sizeclass (sizeclass_id) MATCH SIMPLE
|
411
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
412
|
CONSTRAINT taxonbinmethod_stratumtype_id FOREIGN KEY (stratumtype_id)
|
413
|
REFERENCES stratumtype (stratumtype_id) MATCH SIMPLE
|
414
|
ON UPDATE CASCADE ON DELETE CASCADE
|
415
|
);
|