Project

General

Profile

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 namedplace
62
(
63
  namedplace_id serial NOT NULL,
64
  placesystem character varying(50),
65
  placename character varying(100) NOT NULL,
66
  placedescription text,
67
  placecode character varying(15),
68
  owner character varying(100),
69
  reference_id integer,
70
  d_obscount integer,
71
  accessioncode character varying(255),
72
  CONSTRAINT namedplace_pkey PRIMARY KEY (namedplace_id ),
73
  CONSTRAINT namedplace_reference_id FOREIGN KEY (reference_id)
74
      REFERENCES reference (reference_id) MATCH SIMPLE
75
      ON UPDATE CASCADE ON DELETE CASCADE,
76
  CONSTRAINT namedplace_keys UNIQUE (placesystem , placename )
77
);
78

    
79
CREATE TABLE project
80
(
81
  project_id serial NOT NULL,
82
  projectname character varying(150) NOT NULL,
83
  projectdescription text,
84
  startdate timestamp with time zone,
85
  stopdate timestamp with time zone,
86
  d_obscount integer,
87
  d_lastlocationaddeddate timestamp with time zone,
88
  accessioncode character varying(255),
89
  CONSTRAINT project_pkey PRIMARY KEY (project_id ),
90
  CONSTRAINT project_keys UNIQUE (projectname , startdate , stopdate )
91
);
92

    
93
-- New tables
94

    
95
CREATE TABLE location
96
(
97
  location_id serial NOT NULL,
98
  sourceid character varying(30),
99
  reference_id integer,
100
  parent_id integer,
101
  reallatitude double precision,
102
  reallongitude double precision,
103
  locationaccuracy double precision,
104
  confidentialitystatus integer NOT NULL,
105
  confidentialityreason character varying(200),
106
  latitude double precision,
107
  longitude double precision,
108
  -- ...
109
  accessioncode character varying(255),
110
  sublocationxposition double precision,
111
  sublocationyposition double precision,
112
  namedplace_id integer,
113
  CONSTRAINT location_pkey PRIMARY KEY (location_id ),
114
  CONSTRAINT location_namedplace_id FOREIGN KEY (namedplace_id)
115
      REFERENCES namedplace (namedplace_id) MATCH SIMPLE
116
      ON UPDATE CASCADE ON DELETE CASCADE,
117
  CONSTRAINT location_parent_id FOREIGN KEY (parent_id)
118
      REFERENCES location (location_id) MATCH SIMPLE
119
      ON UPDATE CASCADE ON DELETE CASCADE,
120
  CONSTRAINT location_reference_id FOREIGN KEY (reference_id)
121
      REFERENCES reference (reference_id) MATCH SIMPLE
122
      ON UPDATE CASCADE ON DELETE CASCADE,
123
  CONSTRAINT location_keys UNIQUE (reference_id , parent_id , sourceid )
124
);
125

    
126
CREATE TABLE locationevent -- VegBank's observation table.
127
(
128
  locationevent_id serial NOT NULL,
129
  previous_id integer,
130
  location_id integer NOT NULL,
131
  project_id integer,
132
  sourceid character varying(30),
133
  -- ...
134
  accessioncode character varying(255),
135
  CONSTRAINT locationevent_pkey PRIMARY KEY (locationevent_id ),
136
  CONSTRAINT locationevent_location_id FOREIGN KEY (location_id)
137
      REFERENCES location (location_id) MATCH SIMPLE
138
      ON UPDATE CASCADE ON DELETE CASCADE,
139
  CONSTRAINT locationevent_project_id FOREIGN KEY (project_id)
140
      REFERENCES project (project_id) MATCH SIMPLE
141
      ON UPDATE CASCADE ON DELETE CASCADE,
142
  CONSTRAINT locationevent_keys UNIQUE (location_id , project_id , sourceid )
143
);
144

    
145
CREATE TABLE taxonoccurrence -- VegBank's taxonobservation table.
146
(
147
  taxonoccurrence_id serial NOT NULL,
148
  locationevent_id integer NOT NULL,
149
  authorplantname character varying(255),
150
  reference_id integer,
151
  taxoninferencearea double precision,
152
  emb_taxonoccurrence integer,
153
  -- ...
154
  accessioncode character varying(255),
155
  CONSTRAINT taxonoccurrence_pkey PRIMARY KEY (taxonoccurrence_id ),
156
  CONSTRAINT taxonoccurrence_locationevent_id FOREIGN KEY (locationevent_id)
157
      REFERENCES locationevent (locationevent_id) MATCH SIMPLE
158
      ON UPDATE CASCADE ON DELETE CASCADE,
159
  CONSTRAINT taxonoccurrence_reference_id FOREIGN KEY (reference_id)
160
      REFERENCES reference (reference_id) MATCH SIMPLE
161
      ON UPDATE CASCADE ON DELETE CASCADE
162
);
163

    
164
CREATE TABLE aggregateoccurrence -- VegBank's taxonimportance table.
165
(
166
  aggregateoccurrence_id serial NOT NULL,
167
  taxonoccurrence_id integer NOT NULL,
168
  taxonbin_id integer,
169
  cover double precision,
170
  basalarea double precision,
171
  biomass double precision,
172
  inferencearea double precision,
173
  stratumbase double precision,
174
  stratumheight double precision,
175
  emb_aggregateoccurrence integer,
176
  covercode character varying(10),
177
  count integer NOT NULL,
178
  accessioncode character varying(255),
179
  CONSTRAINT aggregateoccurrence_pkey PRIMARY KEY (aggregateoccurrence_id ),
180
  CONSTRAINT aggregateoccurrence_taxonbin_id FOREIGN KEY (taxonbin_id)
181
      REFERENCES taxonbin (taxonbin_id) MATCH SIMPLE
182
      ON UPDATE CASCADE ON DELETE CASCADE,
183
  CONSTRAINT aggregateoccurrence_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
184
      REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
185
      ON UPDATE CASCADE ON DELETE CASCADE,
186
  CONSTRAINT aggregateoccurrence_keys UNIQUE (taxonoccurrence_id , taxonbin_id )
187
);
188

    
189
CREATE TABLE individualplant -- VegBank's stemcount table.
190
(
191
  individualplant_id serial NOT NULL,
192
  aggregateoccurrence_id integer NOT NULL,
193
  height double precision,
194
  heightaccuracy double precision,
195
  emb_individualplant integer,
196
  sourceid character varying(20),
197
  accessioncode character varying(255),
198
  stemcount integer,
199
  CONSTRAINT individualplant_pkey PRIMARY KEY (individualplant_id ),
200
  CONSTRAINT individualplant_aggregateoccurrence_id FOREIGN KEY (aggregateoccurrence_id)
201
      REFERENCES aggregateoccurrence (aggregateoccurrence_id) MATCH SIMPLE
202
      ON UPDATE CASCADE ON DELETE CASCADE,
203
  CONSTRAINT individualplant_keys UNIQUE (aggregateoccurrence_id , sourceid )
204
);
205

    
206
CREATE TABLE stem -- VegBank's stemlocation table.
207
(
208
  stem_id serial NOT NULL,
209
  individualplant_id integer NOT NULL,
210
  sourceid character varying(20),
211
  xposition double precision,
212
  yposition double precision,
213
  health character varying(50),
214
  emb_stem integer,
215
  diameter double precision,
216
  height double precision,
217
  heightaccuracy double precision,
218
  age double precision,
219
  accessioncode character varying(255),
220
  CONSTRAINT stem_pkey PRIMARY KEY (stem_id ),
221
  CONSTRAINT stem_individualplant_id FOREIGN KEY (individualplant_id)
222
      REFERENCES individualplant (individualplant_id) MATCH SIMPLE
223
      ON UPDATE CASCADE ON DELETE CASCADE,
224
  CONSTRAINT stem_keys UNIQUE (individualplant_id , sourceid )
225
);
226

    
227
CREATE TABLE specimen -- A herbarium specimen. Contains Darwin Core specimen data.
228
(
229
  specimen_id serial NOT NULL,
230
  individualplant_id integer,
231
  reference_id integer NOT NULL,
232
  collectioncode_dwc character varying(255),
233
  catalognumber_dwc character varying(255),
234
  collectiondate timestamp with time zone,
235
  collector_id integer,
236
  museum_id integer,
237
  sourceaccessionnumber character varying(100),
238
  accessioncode character varying(255),
239
  taxonoccurrence_id integer,
240
  CONSTRAINT specimen_pkey PRIMARY KEY (specimen_id ),
241
  CONSTRAINT specimen_collector_id FOREIGN KEY (collector_id)
242
      REFERENCES party (party_id) MATCH SIMPLE
243
      ON UPDATE CASCADE ON DELETE CASCADE,
244
  CONSTRAINT specimen_individualplant_id_fkey FOREIGN KEY (individualplant_id)
245
      REFERENCES individualplant (individualplant_id) MATCH SIMPLE
246
      ON UPDATE CASCADE ON DELETE CASCADE,
247
  CONSTRAINT specimen_museum_id FOREIGN KEY (museum_id)
248
      REFERENCES party (party_id) MATCH SIMPLE
249
      ON UPDATE CASCADE ON DELETE CASCADE,
250
  CONSTRAINT specimen_reference_id_fkey FOREIGN KEY (reference_id)
251
      REFERENCES reference (reference_id) MATCH SIMPLE
252
      ON UPDATE CASCADE ON DELETE CASCADE,
253
  CONSTRAINT specimen_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
254
      REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
255
      ON UPDATE CASCADE ON DELETE CASCADE,
256
  CONSTRAINT specimen_keys UNIQUE (reference_id , collectioncode_dwc , catalognumber_dwc )
257
);
258

    
259
CREATE TABLE taxondetermination -- VegBank's taxoninterpretation table.
260
(
261
  taxondetermination_id serial NOT NULL,
262
  taxonoccurrence_id integer NOT NULL,
263
  plantconcept_id integer NOT NULL,
264
  party_id integer NOT NULL,
265
  role_id integer NOT NULL,
266
  determinationtype character varying(30),
267
  reference_id integer,
268
  originaldetermination boolean NOT NULL,
269
  currentdetermination boolean NOT NULL,
270
  taxonfit character varying(50),
271
  taxonconfidence character varying(50),
272
  grouptype character varying(20),
273
  notes text,
274
  notespublic boolean,
275
  notesmgt boolean,
276
  revisions boolean,
277
  determinationdate timestamp with time zone NOT NULL,
278
  emb_taxondetermination integer,
279
  accessioncode character varying(255),
280
  CONSTRAINT taxondetermination_pkey PRIMARY KEY (taxondetermination_id ),
281
  CONSTRAINT taxondetermination_party_id FOREIGN KEY (party_id)
282
      REFERENCES party (party_id) MATCH SIMPLE
283
      ON UPDATE CASCADE ON DELETE CASCADE,
284
  CONSTRAINT taxondetermination_plantconcept_id FOREIGN KEY (plantconcept_id)
285
      REFERENCES plantconcept (plantconcept_id) MATCH SIMPLE
286
      ON UPDATE CASCADE ON DELETE CASCADE,
287
  CONSTRAINT taxondetermination_reference_id FOREIGN KEY (reference_id)
288
      REFERENCES reference (reference_id) MATCH SIMPLE
289
      ON UPDATE CASCADE ON DELETE CASCADE,
290
  CONSTRAINT taxondetermination_role_id FOREIGN KEY (role_id)
291
      REFERENCES aux_role (role_id) MATCH SIMPLE
292
      ON UPDATE CASCADE ON DELETE CASCADE,
293
  CONSTRAINT taxondetermination_taxonoccurrence_id FOREIGN KEY (taxonoccurrence_id)
294
      REFERENCES taxonoccurrence (taxonoccurrence_id) MATCH SIMPLE
295
      ON UPDATE CASCADE ON DELETE CASCADE
296
);
297

    
298
CREATE TABLE sizeclass -- A range of size measurements used to aggregate organisms.
299
(
300
  sizeclass_id serial NOT NULL,
301
  mindiameter double precision,
302
  diameteraccuracy double precision,
303
  minheight double precision,
304
  heightaccuracy double precision,
305
  maxdiameter double precision,
306
  maxheight double precision,
307
  accessioncode character varying(255),
308
  CONSTRAINT sizeclass_pkey PRIMARY KEY (sizeclass_id )
309
);
310

    
311
CREATE TABLE taxonbin -- Defines a set of aggregate measurements. Used by aggregateoccurrence to define how measurements were aggregated.
312
(
313
  taxonbin_id integer NOT NULL,
314
  label character varying(255) NOT NULL,
315
  stratum_id integer,
316
  sizeclass_id integer,
317
  coverindex_id integer,
318
  accessioncode character varying(255),
319
  CONSTRAINT taxonbin_pkey PRIMARY KEY (taxonbin_id ),
320
  CONSTRAINT taxonbin_sizeclass_id FOREIGN KEY (sizeclass_id)
321
      REFERENCES sizeclass (sizeclass_id) MATCH SIMPLE
322
      ON UPDATE CASCADE ON DELETE CASCADE
323
);
(4-4/8)