Project

General

Profile

1
-- Existing tables
2

    
3
CREATE TABLE role
4
(
5
  role_id int(11) NOT NULL AUTO_INCREMENT,
6
  rolecode character varying(30) NOT NULL,
7
  roledescription character varying(200),
8
  CONSTRAINT role_pkey PRIMARY KEY (role_id )
9
);
10

    
11
CREATE TABLE reference
12
(
13
  reference_id int(11) NOT NULL AUTO_INCREMENT,
14
  shortname character varying(250),
15
  fulltext__ text,
16
  referencetype character varying(250)
17
);
18

    
19
CREATE TABLE party
20
(
21
  party_id int(11) NOT NULL AUTO_INCREMENT,
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 int(11) NOT NULL AUTO_INCREMENT,
32
  plantname character varying(255) NOT NULL,
33
  reference_id int(11),
34
  dateentered timestamp NULL 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 int(11) NOT NULL AUTO_INCREMENT,
44
  plantname_id int(11) NOT NULL,
45
  reference_id int(11),
46
  plantcode character varying(23),
47
  plantdescription text,
48
  d_obscount int(11),
49
  d_currentaccepted int(1),
50
  accessioncode character varying(255),
51
  CONSTRAINT plantconcept_pkey PRIMARY KEY (plantconcept_id ),
52
  CONSTRAINT plantconcept_plantname_id FOREIGN KEY (plantname_id)
53
      REFERENCES plantname (plantname_id) MATCH SIMPLE
54
      ON UPDATE CASCADE ON DELETE CASCADE,
55
  CONSTRAINT plantconcept_reference_id FOREIGN KEY (reference_id)
56
      REFERENCES reference (reference_id) MATCH SIMPLE
57
      ON UPDATE CASCADE ON DELETE CASCADE
58
);
59

    
60
CREATE TABLE stratummethod
61
(
62
  stratummethod_id int(11) NOT NULL AUTO_INCREMENT,
63
  reference_id int(11),
64
  stratummethodname character varying(30) NOT NULL,
65
  stratummethoddescription text,
66
  stratumassignment character varying(50),
67
  accessioncode character varying(255),
68
  CONSTRAINT stratummethod_pkey PRIMARY KEY (stratummethod_id ),
69
  CONSTRAINT stratummethod_reference_id FOREIGN KEY (reference_id)
70
      REFERENCES reference (reference_id) MATCH SIMPLE
71
      ON UPDATE CASCADE ON DELETE CASCADE
72
);
73

    
74
CREATE TABLE stratumtype
75
(
76
  stratumtype_id int(11) NOT NULL AUTO_INCREMENT,
77
  stratummethod_id int(11) NOT NULL,
78
  stratumindex character varying(10),
79
  stratumname character varying(30),
80
  stratumdescription text,
81
  CONSTRAINT stratumtype_pkey PRIMARY KEY (stratumtype_id ),
82
  CONSTRAINT stratumtype_stratummethod_id FOREIGN KEY (stratummethod_id)
83
      REFERENCES stratummethod (stratummethod_id) MATCH SIMPLE
84
      ON UPDATE CASCADE ON DELETE CASCADE
85
);
86

    
87
CREATE TABLE namedplace
88
(
89
  namedplace_id int(11) NOT NULL AUTO_INCREMENT,
90
  placesystem character varying(50),
91
  placename character varying(100) NOT NULL,
92
  placedescription text,
93
  placecode character varying(15),
94
  owner character varying(100),
95
  reference_id int(11),
96
  d_obscount int(11),
97
  accessioncode character varying(255),
98
  CONSTRAINT namedplace_pkey PRIMARY KEY (namedplace_id ),
99
  CONSTRAINT namedplace_reference_id FOREIGN KEY (reference_id)
100
      REFERENCES reference (reference_id) MATCH SIMPLE
101
      ON UPDATE CASCADE ON DELETE CASCADE,
102
  CONSTRAINT namedplace_keys UNIQUE (placesystem , placename )
103
);
104

    
105
CREATE TABLE locationplace
106
(
107
  locationplace_id int(11) NOT NULL AUTO_INCREMENT,
108
  location_id int(11) NOT NULL,
109
  calculated int(1),
110
  namedplace_id int(11) NOT NULL,
111
  CONSTRAINT locationplace_pkey PRIMARY KEY (locationplace_id ),
112
  CONSTRAINT locationplace_location_id FOREIGN KEY (location_id)
113
      REFERENCES location (location_id) MATCH SIMPLE
114
      ON UPDATE CASCADE ON DELETE CASCADE,
115
  CONSTRAINT locationplace_namedplace_id FOREIGN KEY (namedplace_id)
116
      REFERENCES namedplace (namedplace_id) MATCH SIMPLE
117
      ON UPDATE CASCADE ON DELETE CASCADE,
118
  CONSTRAINT locationplace_keys UNIQUE (location_id , namedplace_id )
119
);
120

    
121
CREATE TABLE project
122
(
123
  project_id int(11) NOT NULL AUTO_INCREMENT,
124
  projectname character varying(150) NOT NULL,
125
  projectdescription text,
126
  startdate timestamp NULL,
127
  stopdate timestamp NULL,
128
  d_obscount int(11),
129
  d_lastlocationaddeddate timestamp NULL,
130
  accessioncode character varying(255),
131
  CONSTRAINT project_pkey PRIMARY KEY (project_id ),
132
  CONSTRAINT project_keys UNIQUE (projectname , startdate , stopdate )
133
);
134

    
135
-- New tables
136

    
137
CREATE TABLE location
138
(
139
  location_id int(11) NOT NULL AUTO_INCREMENT,
140
  authorlocationcode character varying(30),
141
  reference_id int(11),
142
  parent_id int(11),
143
  reallatitude double precision,
144
  reallongitude double precision,
145
  locationaccuracy double precision,
146
  confidentialitystatus int(11) NOT NULL DEFAULT 0,
147
  confidentialityreason character varying(200),
148
  publiclatitude double precision,
149
  publiclongitude double precision,
150
  `... (truncated) ...` int(11),
151
  accessioncode character varying(255),
152
  sublocationxposition double precision,
153
  sublocationyposition double precision,
154
  namedplace_id int(11),
155
  CONSTRAINT location_pkey PRIMARY KEY (location_id ),
156
  CONSTRAINT location_namedplace_id FOREIGN KEY (namedplace_id)
157
      REFERENCES namedplace (namedplace_id) MATCH SIMPLE
158
      ON UPDATE CASCADE ON DELETE CASCADE,
159
  CONSTRAINT location_parent_id FOREIGN KEY (parent_id)
160
      REFERENCES location (location_id) MATCH SIMPLE
161
      ON UPDATE CASCADE ON DELETE CASCADE,
162
  CONSTRAINT location_reference_id FOREIGN KEY (reference_id)
163
      REFERENCES reference (reference_id) MATCH SIMPLE
164
      ON UPDATE CASCADE ON DELETE CASCADE,
165
  CONSTRAINT location_keys_code UNIQUE (reference_id , authorlocationcode ),
166
  CONSTRAINT location_keys_coords UNIQUE (reference_id , reallatitude , reallongitude ),
167
  CONSTRAINT location_keys_subplot_code UNIQUE (parent_id , authorlocationcode ),
168
  CONSTRAINT location_keys_subplot_coords UNIQUE (parent_id , sublocationxposition , sublocationyposition )
169
);
170

    
171
CREATE TABLE locationevent -- VegBank's observation table.
172
(
173
  locationevent_id int(11) NOT NULL AUTO_INCREMENT,
174
  previous_id int(11),
175
  location_id int(11),
176
  project_id int(11),
177
  authoreventcode character varying(30),
178
  `... (truncated) ...` int(11),
179
  accessioncode character varying(255),
180
  sourceaccessioncode character varying(100),
181
  CONSTRAINT locationevent_pkey PRIMARY KEY (locationevent_id ),
182
  CONSTRAINT locationevent_location_id FOREIGN KEY (location_id)
183
      REFERENCES location (location_id) MATCH SIMPLE
184
      ON UPDATE CASCADE ON DELETE CASCADE,
185
  CONSTRAINT locationevent_project_id FOREIGN KEY (project_id)
186
      REFERENCES project (project_id) MATCH SIMPLE
187
      ON UPDATE CASCADE ON DELETE CASCADE,
188
  CONSTRAINT locationevent_keys_accessioncode UNIQUE (location_id , project_id , sourceaccessioncode ),
189
  CONSTRAINT locationevent_keys_code UNIQUE (location_id , project_id , authoreventcode )
190
);
191

    
192
CREATE TABLE taxonoccurrence -- VegBank's taxonobservation table.
193
(
194
  taxonoccurrence_id int(11) NOT NULL AUTO_INCREMENT,
195
  locationevent_id int(11),
196
  authorplantname character varying(255),
197
  reference_id int(11),
198
  taxoninferencearea double precision,
199
  emb_taxonoccurrence int(11),
200
  `... (truncated) ...` int(11),
201
  accessioncode character varying(255),
202
  CONSTRAINT taxonoccurrence_pkey PRIMARY KEY (taxonoccurrence_id ),
203
  CONSTRAINT taxonoccurrence_locationevent_id FOREIGN KEY (locationevent_id)
204
      REFERENCES locationevent (locationevent_id) MATCH SIMPLE
205
      ON UPDATE CASCADE ON DELETE CASCADE,
206
  CONSTRAINT taxonoccurrence_reference_id FOREIGN KEY (reference_id)
207
      REFERENCES reference (reference_id) MATCH SIMPLE
208
      ON UPDATE CASCADE ON DELETE CASCADE
209
);
210

    
211
CREATE TABLE aggregateoccurrence -- VegBank's taxonimportance table.
212
(
213
  aggregateoccurrence_id int(11) NOT NULL AUTO_INCREMENT,
214
  taxonoccurrence_id int(11) NOT NULL,
215
  taxonbinmethod_id int(11),
216
  cover double precision,
217
  basalarea double precision,
218
  biomass double precision,
219
  inferencearea double precision,
220
  stratumbase double precision,
221
  stratumheight double precision,
222
  emb_aggregateoccurrence int(11),
223
  covercode character varying(10),
224
  count int(11),
225
  accessioncode character varying(255),
226
  sourceaccessioncode character varying(100),
227
  plantobservation_id int(11),
228
  stratum_id int(11),
229
  sizeclass_id int(11),
230
  coverindex_id int(11),
231
  CONSTRAINT aggregateoccurrence_pkey PRIMARY KEY (aggregateoccurrence_id ),
232
  CONSTRAINT aggregateoccurrence_plantobservation_id FOREIGN KEY (plantobservation_id)
233
      REFERENCES plantobservation (plantobservation_id) MATCH SIMPLE
234
      ON UPDATE CASCADE ON DELETE CASCADE,
235
  CONSTRAINT aggregateoccurrence_sizeclass_id FOREIGN KEY (sizeclass_id)
236
      REFERENCES sizeclass (sizeclass_id) MATCH SIMPLE
237
      ON UPDATE CASCADE ON DELETE CASCADE,
238
  CONSTRAINT aggregateoccurrence_stratum_id FOREIGN KEY (stratum_id)
239
      REFERENCES stratum (stratum_id) MATCH SIMPLE
240
      ON UPDATE CASCADE ON DELETE CASCADE,
241
  CONSTRAINT aggregateoccurrence_taxonbinmethod_id FOREIGN KEY (taxonbinmethod_id)
242
      REFERENCES taxonbinmethod (taxonbinmethod_id) MATCH SIMPLE
243
      ON UPDATE CASCADE ON DELETE CASCADE,
244
  CONSTRAINT aggregateoccurrence_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
245
      REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
246
      ON UPDATE CASCADE ON DELETE CASCADE,
247
  CONSTRAINT aggregateoccurrence_keys_accessioncode UNIQUE (taxonoccurrence_id , sourceaccessioncode ),
248
  CONSTRAINT aggregateoccurrence_keys_method UNIQUE (taxonoccurrence_id , taxonbinmethod_id )
249
);
250

    
251
CREATE TABLE plant -- A physical, tagged plant.
252
(
253
  plant_id int(11) NOT NULL AUTO_INCREMENT,
254
  CONSTRAINT plant_pkey PRIMARY KEY (plant_id )
255
);
256

    
257
CREATE TABLE planttag
258
(
259
  planttag_id int(11) NOT NULL AUTO_INCREMENT,
260
  plant_id int(11) NOT NULL,
261
  tag character varying(255) NOT NULL,
262
  CONSTRAINT planttag_pkey PRIMARY KEY (planttag_id ),
263
  CONSTRAINT planttag_plant_id FOREIGN KEY (plant_id)
264
      REFERENCES plant (plant_id) MATCH SIMPLE
265
      ON UPDATE CASCADE ON DELETE CASCADE,
266
  CONSTRAINT planttag_keys UNIQUE (plant_id , tag )
267
);
268

    
269
CREATE TABLE plantobservation -- VegBank's stemcount table.
270
(
271
  plantobservation_id int(11) NOT NULL AUTO_INCREMENT,
272
  aggregateoccurrence_id int(11) NOT NULL,
273
  overallheight double precision,
274
  overallheightaccuracy double precision,
275
  emb_plantobservation int(11),
276
  authorplantcode character varying(20),
277
  accessioncode character varying(255),
278
  stemcount int(11),
279
  sourceaccessioncode character varying(100),
280
  plant_id int(11),
281
  CONSTRAINT plantobservation_pkey PRIMARY KEY (plantobservation_id ),
282
  CONSTRAINT plantobservation_aggregateoccurrence_id FOREIGN KEY (aggregateoccurrence_id)
283
      REFERENCES aggregateoccurrence (aggregateoccurrence_id) MATCH SIMPLE
284
      ON UPDATE CASCADE ON DELETE CASCADE,
285
  CONSTRAINT plantobservation_plant_id FOREIGN KEY (plant_id)
286
      REFERENCES plant (plant_id) MATCH SIMPLE
287
      ON UPDATE CASCADE ON DELETE CASCADE,
288
  CONSTRAINT plantobservation_aggregateoccurrence_id_1_to_1 UNIQUE (aggregateoccurrence_id )
289
);
290

    
291
CREATE TABLE stemobservation -- VegBank's stemlocation table.
292
(
293
  stemobservation_id int(11) NOT NULL AUTO_INCREMENT,
294
  plantobservation_id int(11) NOT NULL,
295
  authorstemcode character varying(20),
296
  xposition double precision,
297
  yposition double precision,
298
  health character varying(50),
299
  emb_stemobservation int(11),
300
  diameter double precision,
301
  height double precision,
302
  heightaccuracy double precision,
303
  age double precision,
304
  accessioncode character varying(255),
305
  diameteraccuracy double precision,
306
  sourceaccessioncode character varying(100),
307
  CONSTRAINT stemobservation_pkey PRIMARY KEY (stemobservation_id ),
308
  CONSTRAINT stemobservation_plantobservation_id FOREIGN KEY (plantobservation_id)
309
      REFERENCES plantobservation (plantobservation_id) MATCH SIMPLE
310
      ON UPDATE CASCADE ON DELETE CASCADE,
311
  CONSTRAINT stemobservation_keys_accessioncode UNIQUE (plantobservation_id , sourceaccessioncode ),
312
  CONSTRAINT stemobservation_keys_code UNIQUE (plantobservation_id , authorstemcode )
313
);
314

    
315
CREATE TABLE specimen -- A physical specimen collected from a plant. Used to link replicates of the same specimen together.
316
(
317
  specimen_id int(11) NOT NULL AUTO_INCREMENT,
318
  CONSTRAINT specimen_pkey PRIMARY KEY (specimen_id )
319
);
320

    
321
CREATE TABLE specimenreplicate -- A herbarium's replicate of a specimen. Contains Darwin Core specimen data.
322
(
323
  specimenreplicate_id int(11) NOT NULL AUTO_INCREMENT,
324
  reference_id int(11) NOT NULL,
325
  collectioncode_dwc character varying(255), -- The code for the collection that the specimenreplicate is from.
326
  catalognumber_dwc character varying(255),
327
  collectiondate timestamp NULL,
328
  museum_id int(11),
329
  sourceaccessioncode character varying(100),
330
  accessioncode character varying(255),
331
  taxonoccurrence_id int(11) NOT NULL,
332
  verbatimcollectorname character varying(255),
333
  collectionnumber character varying(255), -- The number of the specimenreplicate within the collection.
334
  specimen_id int(11),
335
  CONSTRAINT specimenreplicate_pkey PRIMARY KEY (specimenreplicate_id ),
336
  CONSTRAINT specimenreplicate_museum_id FOREIGN KEY (museum_id)
337
      REFERENCES party (party_id) MATCH SIMPLE
338
      ON UPDATE CASCADE ON DELETE CASCADE,
339
  CONSTRAINT specimenreplicate_reference_id_fkey FOREIGN KEY (reference_id)
340
      REFERENCES reference (reference_id) MATCH SIMPLE
341
      ON UPDATE CASCADE ON DELETE CASCADE,
342
  CONSTRAINT specimenreplicate_specimen_id FOREIGN KEY (specimen_id)
343
      REFERENCES specimen (specimen_id) MATCH SIMPLE
344
      ON UPDATE CASCADE ON DELETE CASCADE,
345
  CONSTRAINT specimenreplicate_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
346
      REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
347
      ON UPDATE CASCADE ON DELETE CASCADE,
348
  CONSTRAINT specimenreplicate_keys_accessioncode UNIQUE (reference_id , collectioncode_dwc , sourceaccessioncode ),
349
  CONSTRAINT specimenreplicate_keys_catalognumber UNIQUE (reference_id , collectioncode_dwc , catalognumber_dwc ),
350
  CONSTRAINT specimenreplicate_keys_collectionnumber UNIQUE (reference_id , collectioncode_dwc , collectionnumber )
351
);
352

    
353
CREATE TABLE voucher
354
(
355
  voucher_id int(11) NOT NULL AUTO_INCREMENT,
356
  taxonoccurrence_id int(11) NOT NULL,
357
  specimenreplicate_id int(11) NOT NULL,
358
  accessioncode character varying(255),
359
  CONSTRAINT voucher_pkey PRIMARY KEY (voucher_id ),
360
  CONSTRAINT voucher_specimenreplicate_id FOREIGN KEY (specimenreplicate_id)
361
      REFERENCES specimenreplicate (specimenreplicate_id) MATCH SIMPLE
362
      ON UPDATE CASCADE ON DELETE CASCADE,
363
  CONSTRAINT voucher_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
364
      REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
365
      ON UPDATE CASCADE ON DELETE CASCADE,
366
  CONSTRAINT voucher_keys UNIQUE (taxonoccurrence_id , specimenreplicate_id )
367
);
368

    
369
CREATE TABLE taxondetermination -- VegBank's taxoninterpretation table.
370
(
371
  taxondetermination_id int(11) NOT NULL AUTO_INCREMENT,
372
  taxonoccurrence_id int(11) NOT NULL,
373
  plantconcept_id int(11) NOT NULL,
374
  party_id int(11),
375
  role_id int(11) NOT NULL,
376
  determinationtype character varying(30),
377
  reference_id int(11),
378
  isoriginal int(1) NOT NULL DEFAULT false,
379
  iscurrent int(1) NOT NULL DEFAULT false,
380
  taxonfit character varying(50),
381
  taxonconfidence character varying(50),
382
  grouptype character varying(20),
383
  notes text,
384
  notespublic int(1),
385
  notesmgt int(1),
386
  revisions int(1),
387
  determinationdate timestamp NULL,
388
  emb_taxondetermination int(11),
389
  accessioncode character varying(255),
390
  CONSTRAINT taxondetermination_pkey PRIMARY KEY (taxondetermination_id ),
391
  CONSTRAINT taxondetermination_party_id FOREIGN KEY (party_id)
392
      REFERENCES party (party_id) MATCH SIMPLE
393
      ON UPDATE CASCADE ON DELETE CASCADE,
394
  CONSTRAINT taxondetermination_plantconcept_id FOREIGN KEY (plantconcept_id)
395
      REFERENCES plantconcept (plantconcept_id) MATCH SIMPLE
396
      ON UPDATE CASCADE ON DELETE CASCADE,
397
  CONSTRAINT taxondetermination_reference_id FOREIGN KEY (reference_id)
398
      REFERENCES reference (reference_id) MATCH SIMPLE
399
      ON UPDATE CASCADE ON DELETE CASCADE,
400
  CONSTRAINT taxondetermination_role_id FOREIGN KEY (role_id)
401
      REFERENCES role (role_id) MATCH SIMPLE
402
      ON UPDATE CASCADE ON DELETE CASCADE,
403
  CONSTRAINT taxondetermination_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
404
      REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
405
      ON UPDATE CASCADE ON DELETE CASCADE
406
);
407

    
408
CREATE TABLE stratum
409
(
410
  stratum_id int(11) NOT NULL AUTO_INCREMENT,
411
  locationevent_id int(11) NOT NULL,
412
  stratumtype_id int(11) NOT NULL,
413
  stratumheight double precision,
414
  stratumbase double precision,
415
  stratumcover double precision,
416
  area double precision,
417
  CONSTRAINT stratum_pkey PRIMARY KEY (stratum_id ),
418
  CONSTRAINT stratum_locationevent_id FOREIGN KEY (locationevent_id)
419
      REFERENCES locationevent (locationevent_id) MATCH SIMPLE
420
      ON UPDATE CASCADE ON DELETE CASCADE,
421
  CONSTRAINT stratum_stratumtype_id FOREIGN KEY (stratumtype_id)
422
      REFERENCES stratumtype (stratumtype_id) MATCH SIMPLE
423
      ON UPDATE CASCADE ON DELETE CASCADE
424
);
425

    
426
CREATE TABLE sizeclass -- A range of size measurements used to aggregate organisms.
427
(
428
  sizeclass_id int(11) NOT NULL AUTO_INCREMENT,
429
  mindiameter double precision,
430
  minheight double precision,
431
  maxdiameter double precision,
432
  maxheight double precision,
433
  accessioncode character varying(255),
434
  CONSTRAINT sizeclass_pkey PRIMARY KEY (sizeclass_id )
435
);
436

    
437
CREATE TABLE taxonbinmethod
438
(
439
  taxonbinmethod_id int(11) NOT NULL,
440
  label character varying(255),
441
  stratumtype_id int(11),
442
  sizeclass_id int(11),
443
  coverindex_id int(11),
444
  accessioncode character varying(255),
445
  CONSTRAINT taxonbinmethod_pkey PRIMARY KEY (taxonbinmethod_id ),
446
  CONSTRAINT taxonbinmethod_sizeclass_id FOREIGN KEY (sizeclass_id)
447
      REFERENCES sizeclass (sizeclass_id) MATCH SIMPLE
448
      ON UPDATE CASCADE ON DELETE CASCADE,
449
  CONSTRAINT taxonbinmethod_stratumtype_id FOREIGN KEY (stratumtype_id)
450
      REFERENCES stratumtype (stratumtype_id) MATCH SIMPLE
451
      ON UPDATE CASCADE ON DELETE CASCADE
452
);
(7-7/12)