Project

General

Profile

« Previous | Next » 

Revision 10778

inputs/.TNRS/schema.sql: generate from the DB using `rm=1 inputs/.TNRS/schema.sql.run export_` instead of being a hand-edited file. this makes it much easier to edit the (now frequently-changing) TNRS schema directly in pgAdmin (which is graphical), rather than having to manually copy SQL changes from pgAdmin to the file.

View differences:

inputs/.TNRS/schema.sql
1
CREATE TABLE client_version
2
(
3
  id text NOT NULL,
4
  global_rev integer NOT NULL, -- from `svn info .` > Last Changed Rev
5
  "/lib/tnrs.py rev" integer, -- from `svn info lib/tnrs.py` > Last Changed Rev
6
  "/bin/tnrs_db rev" integer, -- from `svn info bin/tnrs_db` > Last Changed Rev
7
  CONSTRAINT client_version_pkey PRIMARY KEY (id )
8
)
9
WITH (
10
  OIDS=FALSE
11
);
12
COMMENT ON TABLE client_version
13
  IS 'contains svn revisions';
14
COMMENT ON COLUMN client_version.global_rev IS 'from `svn info .` > Last Changed Rev';
15
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS 'from `svn info lib/tnrs.py` > Last Changed Rev';
16
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS 'from `svn info bin/tnrs_db` > Last Changed Rev';
1
--
2
-- PostgreSQL database dump
3
--
17 4

  
5
SET statement_timeout = 0;
6
SET client_encoding = 'UTF8';
7
SET standard_conforming_strings = on;
8
SET check_function_bodies = false;
9
SET client_min_messages = warning;
10

  
18 11
--
12
-- Name: TNRS; Type: SCHEMA; Schema: -; Owner: -
13
--
19 14

  
20
CREATE TABLE batch
21
(
22
  id text NOT NULL,
23
  id_by_time text,
24
  time_submitted timestamp with time zone DEFAULT now(),
25
  client_version text,
26
  CONSTRAINT batch_pkey PRIMARY KEY (id ),
27
  CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version)
28
      REFERENCES client_version (id) MATCH SIMPLE
29
      ON UPDATE CASCADE ON DELETE CASCADE,
30
  CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time )
31
)
32
WITH (
33
  OIDS=FALSE
34
);
15
--CREATE SCHEMA "TNRS";
35 16

  
36 17

  
37
CREATE OR REPLACE FUNCTION batch__fill()
38
  RETURNS trigger AS
39
$BODY$
18
SET search_path = "TNRS", pg_catalog;
19

  
20
--
21
-- Name: batch__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
22
--
23

  
24
CREATE FUNCTION batch__fill() RETURNS trigger
25
    LANGUAGE plpgsql
26
    AS $$
40 27
BEGIN
41 28
	new.id_by_time = new.time_submitted;
42 29
	new.id = COALESCE(new.id, new.id_by_time);
43 30
	RETURN new;
44 31
END;
45
$BODY$
46
  LANGUAGE plpgsql VOLATILE
47
  COST 100;
32
$$;
48 33

  
49
CREATE TRIGGER batch__fill
50
  BEFORE INSERT OR UPDATE
51
  ON batch
52
  FOR EACH ROW
53
  EXECUTE PROCEDURE batch__fill();
54 34

  
55 35
--
36
-- Name: family_is_homonym(text); Type: FUNCTION; Schema: TNRS; Owner: -
37
--
56 38

  
57
CREATE TABLE batch_download_settings
58
(
59
  id text NOT NULL,
60
  "E-mail" text,
61
  "Id" text,
62
  "Job type" text,
63
  "Contains Id" boolean,
64
  "Start time" text,
65
  "Finish time" text,
66
  "TNRS version" text,
67
  "Sources selected" text,
68
  "Match threshold" double precision,
69
  "Classification" text,
70
  "Allow partial matches?" boolean,
71
  "Sort by source" boolean,
72
  "Constrain by higher taxonomy" boolean,
73
  CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id ),
74
  CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id)
75
      REFERENCES "TNRS".batch (id) MATCH SIMPLE
76
      ON UPDATE CASCADE ON DELETE CASCADE
77
)
78
WITH (
79
  OIDS=FALSE
80
);
81
COMMENT ON TABLE batch_download_settings
82
  IS 'stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt';
39
CREATE FUNCTION family_is_homonym(family text) RETURNS boolean
40
    LANGUAGE sql STABLE STRICT
41
    AS $_$
42
SELECT EXISTS(SELECT * FROM "IRMNG".family_homonym_epithet WHERE "taxonNameOrEpithet" = $1)
43
$_$;
83 44

  
45

  
84 46
--
47
-- Name: genus_is_homonym(text); Type: FUNCTION; Schema: TNRS; Owner: -
48
--
85 49

  
86
CREATE OR REPLACE FUNCTION score_ok(score double precision)
87
  RETURNS boolean AS
88
$BODY$
89
SELECT $1 >= 0.8
90
$BODY$
91
  LANGUAGE sql IMMUTABLE STRICT
92
  COST 100;
50
CREATE FUNCTION genus_is_homonym(genus text) RETURNS boolean
51
    LANGUAGE sql STABLE STRICT
52
    AS $_$
53
SELECT EXISTS(SELECT * FROM "IRMNG".genus_homonym_epithet WHERE "taxonNameOrEpithet" = $1)
54
$_$;
93 55

  
94
CREATE OR REPLACE FUNCTION family_is_homonym(family text)
95
  RETURNS boolean AS
96
$BODY$
97
SELECT EXISTS(SELECT * FROM "IRMNG".family_homonym_epithet WHERE "taxonNameOrEpithet" = $1)
98
$BODY$
99
  LANGUAGE sql STABLE STRICT
100
  COST 100;
101 56

  
102
CREATE OR REPLACE FUNCTION genus_is_homonym(genus text)
103
  RETURNS boolean AS
104
$BODY$
105
SELECT EXISTS(SELECT * FROM "IRMNG".genus_homonym_epithet WHERE "taxonNameOrEpithet" = $1)
106
$BODY$
107
  LANGUAGE sql STABLE STRICT
108
  COST 100;
57
--
58
-- Name: score_ok(double precision); Type: FUNCTION; Schema: TNRS; Owner: -
59
--
109 60

  
110
CREATE TABLE tnrs
111
(
112
  batch text NOT NULL DEFAULT now(),
113
  "Name_number" integer NOT NULL,
114
  "Name_submitted" text NOT NULL,
115
  "Overall_score" double precision,
116
  "Name_matched" text,
117
  "Name_matched_rank" text,
118
  "Name_score" double precision,
119
  "Name_matched_author" text,
120
  "Name_matched_url" text,
121
  "Author_matched" text,
122
  "Author_score" double precision,
123
  "Family_matched" text,
124
  "Family_score" double precision,
125
  "Name_matched_accepted_family" text,
126
  "Genus_matched" text,
127
  "Genus_score" double precision,
128
  "Specific_epithet_matched" text,
129
  "Specific_epithet_score" double precision,
130
  "Infraspecific_rank" text,
131
  "Infraspecific_epithet_matched" text,
132
  "Infraspecific_epithet_score" double precision,
133
  "Infraspecific_rank_2" text,
134
  "Infraspecific_epithet_2_matched" text,
135
  "Infraspecific_epithet_2_score" double precision,
136
  "Annotations" text,
137
  "Unmatched_terms" text,
138
  "Taxonomic_status" text,
139
  "Accepted_name" text,
140
  "Accepted_name_author" text,
141
  "Accepted_name_rank" text,
142
  "Accepted_name_url" text,
143
  "Accepted_name_species" text,
144
  "Accepted_name_family" text,
145
  "Selected" text,
146
  "Source" text,
147
  "Warnings" text,
148
  "Accepted_name_lsid" text,
149
  "Accepted_scientific_name" text,
150
  "Max_score" double precision,
151
  "Is_homonym" boolean,
152
  "Is_plant" boolean,
153
  CONSTRAINT tnrs_pkey PRIMARY KEY (batch , "Name_number" ),
154
  CONSTRAINT tnrs_batch_fkey FOREIGN KEY (batch)
155
      REFERENCES batch (id) MATCH SIMPLE
156
      ON UPDATE CASCADE ON DELETE CASCADE,
157
  CONSTRAINT "tnrs_Name_submitted_key" UNIQUE ("Name_submitted" )
158
)
159
WITH (
160
  OIDS=FALSE
161
);
162
COMMENT ON TABLE tnrs
163
  IS 'IMPORTANT: when changing this table''s schema, you must regenerate data.sql:
164
$ <this_file>/../test_taxonomic_names/test_scrub
165
you must also make the same changes on vegbiendev: e.g.
166
$ make backups/TNRS.backup-remake # runtime: 3 min ("real 2m44.277s")
167
SELECT util.set_col_types(''"TNRS".tnrs'', ARRAY[
168
  (''col'', ''new_type'')
169
]::util.col_cast[]);
170
runtime: 9 min ("531282 ms")';
61
CREATE FUNCTION score_ok(score double precision) RETURNS boolean
62
    LANGUAGE sql IMMUTABLE STRICT
63
    AS $_$
64
SELECT $1 >= 0.8
65
$_$;
171 66

  
172
CREATE UNIQUE INDEX tnrs_score_ok
173
  ON tnrs
174
  USING btree
175
  ("Name_submitted" )
176
  WHERE score_ok("Max_score");
177 67

  
178
CREATE OR REPLACE FUNCTION tnrs_populate_fields()
179
  RETURNS trigger AS
180
$BODY$
68
--
69
-- Name: tnrs_populate_fields(); Type: FUNCTION; Schema: TNRS; Owner: -
70
--
71

  
72
CREATE FUNCTION tnrs_populate_fields() RETURNS trigger
73
    LANGUAGE plpgsql
74
    AS $$
181 75
DECLARE
182 76
    "Specific_epithet_is_plant" boolean :=
183 77
        (CASE
......
222 116
    
223 117
    RETURN new;
224 118
END;
225
$BODY$
226
  LANGUAGE plpgsql VOLATILE
227
  COST 100;
119
$$;
120

  
121

  
122
--
123
-- Name: FUNCTION tnrs_populate_fields(); Type: COMMENT; Schema: TNRS; Owner: -
124
--
125

  
228 126
COMMENT ON FUNCTION tnrs_populate_fields() IS 'IMPORTANT: when changing this function, you must regenerate the derived cols:
229 127
UPDATE "TNRS".tnrs SET "Name_submitted" = "Name_submitted"
230 128
runtime: 25 min ("5221748 rows affected, 1524228 ms execution time")
231 129
VACUUM ANALYZE "TNRS".tnrs -- to remove previous rows
232 130
runtime: 1 min ("62350 ms")';
233 131

  
234
CREATE TRIGGER tnrs_populate_fields
235
  BEFORE INSERT OR UPDATE
236
  ON tnrs
237
  FOR EACH ROW
238
  EXECUTE PROCEDURE tnrs_populate_fields();
239 132

  
133
SET default_tablespace = '';
134

  
135
SET default_with_oids = false;
136

  
240 137
--
138
-- Name: tnrs; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
139
--
241 140

  
242
CREATE OR REPLACE VIEW "MatchedTaxon" AS
243
SELECT
244
  "batch" AS "*Name_matched.batch"
245
, "Name_submitted" AS "concatenatedScientificName"
246
, "Name_matched" AS "matchedTaxonName"
247
, "Name_matched_rank" AS "matchedTaxonRank"
248
, "Name_score" AS "*Name_matched.Name_score"
249
, "Name_matched_author" AS "matchedScientificNameAuthorship"
250
, "Name_matched_url" AS "matchedScientificNameID"
251
, "Author_score" AS "*Name_matched.Author_score"
252
, "Family_score" AS "matchedFamilyConfidence_fraction"
253
, COALESCE("Name_matched_accepted_family", "Accepted_name_family") AS "matchedFamily"
254
, "Genus_matched" AS "matchedGenus"
255
, "Genus_score" AS "matchedGenusConfidence_fraction"
256
, "Specific_epithet_matched" AS "matchedSpecificEpithet"
257
, "Specific_epithet_score" AS "matchedSpeciesConfidence_fraction"
258
, "Infraspecific_epithet_matched" AS "matchedInfraspecificEpithet"
259
, "Infraspecific_epithet_score" AS "*Name_matched.Infraspecific_epithet_score"
260
, "Annotations" AS "identificationQualifier"
261
, "Unmatched_terms" AS "morphospeciesSuffix"
262
, "Taxonomic_status" AS "taxonomicStatus"
263
, "Accepted_name" AS "acceptedTaxonName"
264
, "Accepted_name_author" AS "acceptedScientificNameAuthorship"
265
, "Accepted_name_rank" AS "acceptedTaxonRank"
266
, "Accepted_name_url" AS "acceptedScientificNameID"
267
, "Accepted_name_species" AS "*Name_matched.Accepted_name_species"
268
, "Accepted_name_family" AS "acceptedFamily"
269
, "Selected" AS "*Name_matched.Selected"
270
, "Source" AS "*Name_matched.Source"
271
, "Warnings" AS "*Name_matched.Warnings"
272
, "Accepted_name_lsid" AS "*Name_matched.Accepted_name_lsid"
273
, "Accepted_scientific_name" AS "acceptedScientificName"
274
, "Max_score" AS "matchedTaxonConfidence_fraction"
275
FROM tnrs
276
;
141
CREATE TABLE tnrs (
142
    batch text DEFAULT now() NOT NULL,
143
    "Name_number" integer NOT NULL,
144
    "Name_submitted" text NOT NULL,
145
    "Overall_score" double precision,
146
    "Name_matched" text,
147
    "Name_matched_rank" text,
148
    "Name_score" double precision,
149
    "Name_matched_author" text,
150
    "Name_matched_url" text,
151
    "Author_matched" text,
152
    "Author_score" double precision,
153
    "Family_matched" text,
154
    "Family_score" double precision,
155
    "Name_matched_accepted_family" text,
156
    "Genus_matched" text,
157
    "Genus_score" double precision,
158
    "Specific_epithet_matched" text,
159
    "Specific_epithet_score" double precision,
160
    "Infraspecific_rank" text,
161
    "Infraspecific_epithet_matched" text,
162
    "Infraspecific_epithet_score" double precision,
163
    "Infraspecific_rank_2" text,
164
    "Infraspecific_epithet_2_matched" text,
165
    "Infraspecific_epithet_2_score" double precision,
166
    "Annotations" text,
167
    "Unmatched_terms" text,
168
    "Taxonomic_status" text,
169
    "Accepted_name" text,
170
    "Accepted_name_author" text,
171
    "Accepted_name_rank" text,
172
    "Accepted_name_url" text,
173
    "Accepted_name_species" text,
174
    "Accepted_name_family" text,
175
    "Selected" text,
176
    "Source" text,
177
    "Warnings" text,
178
    "Accepted_name_lsid" text,
179
    "Accepted_scientific_name" text,
180
    "Max_score" double precision,
181
    "Is_homonym" boolean,
182
    "Is_plant" boolean
183
);
277 184

  
278
CREATE OR REPLACE VIEW "ValidMatchedTaxon" AS
279
SELECT *
280
FROM "MatchedTaxon"
281
WHERE score_ok("matchedTaxonConfidence_fraction")
282
;
283
COMMENT ON VIEW "ValidMatchedTaxon"
284
  IS 'to update, use * as the column list';
285 185

  
286
CREATE OR REPLACE VIEW "AcceptedTaxon" AS
287
SELECT
288
  "batch" AS "*Accepted_name.batch"
289
, "Name_submitted" AS "acceptedScientificName"
290
, "Genus_matched" AS "acceptedGenus"
291
, "Specific_epithet_matched" AS "acceptedSpecificEpithet"
292
, "Infraspecific_epithet_matched" AS "acceptedInfraspecificEpithet"
293
, "Taxonomic_status" AS "acceptedTaxonomicStatus"
294
, "Selected" AS "*Accepted_name.Selected"
295
, "Source" AS "*Accepted_name.Source"
296
, "Warnings" AS "*Accepted_name.Warnings"
297
, "Accepted_name_lsid" AS "*Accepted_name.Accepted_name_lsid"
298
FROM tnrs
299
;
186
--
187
-- Name: TABLE tnrs; Type: COMMENT; Schema: TNRS; Owner: -
188
--
300 189

  
301
CREATE OR REPLACE VIEW "ScrubbedTaxon" AS
302
SELECT *
303
FROM "ValidMatchedTaxon"
304
NATURAL LEFT JOIN "AcceptedTaxon"
305
;
306
COMMENT ON VIEW "ScrubbedTaxon"
307
  IS 'to update, use * as the column list';
190
COMMENT ON TABLE tnrs IS 'IMPORTANT: when changing this table''s schema, you must regenerate data.sql:
191
$ <this_file>/../test_taxonomic_names/test_scrub
192
you must also make the same changes on vegbiendev: e.g.
193
$ make backups/TNRS.backup-remake # runtime: 3 min ("real 2m44.277s")
194
SELECT util.set_col_types(''"TNRS".tnrs'', ARRAY[
195
  (''col'', ''new_type'')
196
]::util.col_cast[]);
197
runtime: 9 min ("531282 ms")';
198

  
199

  
200
--
201
-- Name: AcceptedTaxon; Type: VIEW; Schema: TNRS; Owner: -
202
--
203

  
204
CREATE VIEW "AcceptedTaxon" AS
205
    SELECT tnrs.batch AS "*Accepted_name.batch", tnrs."Name_submitted" AS "acceptedScientificName", tnrs."Genus_matched" AS "acceptedGenus", tnrs."Specific_epithet_matched" AS "acceptedSpecificEpithet", tnrs."Infraspecific_epithet_matched" AS "acceptedInfraspecificEpithet", tnrs."Taxonomic_status" AS "acceptedTaxonomicStatus", tnrs."Selected" AS "*Accepted_name.Selected", tnrs."Source" AS "*Accepted_name.Source", tnrs."Warnings" AS "*Accepted_name.Warnings", tnrs."Accepted_name_lsid" AS "*Accepted_name.Accepted_name_lsid" FROM tnrs;
206

  
207

  
208
--
209
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
210
--
211

  
212
CREATE VIEW "MatchedTaxon" AS
213
    SELECT tnrs.batch AS "*Name_matched.batch", tnrs."Name_submitted" AS "concatenatedScientificName", tnrs."Name_matched" AS "matchedTaxonName", tnrs."Name_matched_rank" AS "matchedTaxonRank", tnrs."Name_score" AS "*Name_matched.Name_score", tnrs."Name_matched_author" AS "matchedScientificNameAuthorship", tnrs."Name_matched_url" AS "matchedScientificNameID", tnrs."Author_score" AS "*Name_matched.Author_score", tnrs."Family_score" AS "matchedFamilyConfidence_fraction", COALESCE(tnrs."Name_matched_accepted_family", tnrs."Accepted_name_family") AS "matchedFamily", tnrs."Genus_matched" AS "matchedGenus", tnrs."Genus_score" AS "matchedGenusConfidence_fraction", tnrs."Specific_epithet_matched" AS "matchedSpecificEpithet", tnrs."Specific_epithet_score" AS "matchedSpeciesConfidence_fraction", tnrs."Infraspecific_epithet_matched" AS "matchedInfraspecificEpithet", tnrs."Infraspecific_epithet_score" AS "*Name_matched.Infraspecific_epithet_score", tnrs."Annotations" AS "identificationQualifier", tnrs."Unmatched_terms" AS "morphospeciesSuffix", tnrs."Taxonomic_status" AS "taxonomicStatus", tnrs."Accepted_name" AS "acceptedTaxonName", tnrs."Accepted_name_author" AS "acceptedScientificNameAuthorship", tnrs."Accepted_name_rank" AS "acceptedTaxonRank", tnrs."Accepted_name_url" AS "acceptedScientificNameID", tnrs."Accepted_name_species" AS "*Name_matched.Accepted_name_species", tnrs."Accepted_name_family" AS "acceptedFamily", tnrs."Selected" AS "*Name_matched.Selected", tnrs."Source" AS "*Name_matched.Source", tnrs."Warnings" AS "*Name_matched.Warnings", tnrs."Accepted_name_lsid" AS "*Name_matched.Accepted_name_lsid", tnrs."Accepted_scientific_name" AS "acceptedScientificName", tnrs."Max_score" AS "matchedTaxonConfidence_fraction" FROM tnrs;
214

  
215

  
216
--
217
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
218
--
219

  
220
CREATE VIEW "ValidMatchedTaxon" AS
221
    SELECT "MatchedTaxon"."*Name_matched.batch", "MatchedTaxon"."concatenatedScientificName", "MatchedTaxon"."matchedTaxonName", "MatchedTaxon"."matchedTaxonRank", "MatchedTaxon"."*Name_matched.Name_score", "MatchedTaxon"."matchedScientificNameAuthorship", "MatchedTaxon"."matchedScientificNameID", "MatchedTaxon"."*Name_matched.Author_score", "MatchedTaxon"."matchedFamilyConfidence_fraction", "MatchedTaxon"."matchedFamily", "MatchedTaxon"."matchedGenus", "MatchedTaxon"."matchedGenusConfidence_fraction", "MatchedTaxon"."matchedSpecificEpithet", "MatchedTaxon"."matchedSpeciesConfidence_fraction", "MatchedTaxon"."matchedInfraspecificEpithet", "MatchedTaxon"."*Name_matched.Infraspecific_epithet_score", "MatchedTaxon"."identificationQualifier", "MatchedTaxon"."morphospeciesSuffix", "MatchedTaxon"."taxonomicStatus", "MatchedTaxon"."acceptedTaxonName", "MatchedTaxon"."acceptedScientificNameAuthorship", "MatchedTaxon"."acceptedTaxonRank", "MatchedTaxon"."acceptedScientificNameID", "MatchedTaxon"."*Name_matched.Accepted_name_species", "MatchedTaxon"."acceptedFamily", "MatchedTaxon"."*Name_matched.Selected", "MatchedTaxon"."*Name_matched.Source", "MatchedTaxon"."*Name_matched.Warnings", "MatchedTaxon"."*Name_matched.Accepted_name_lsid", "MatchedTaxon"."acceptedScientificName", "MatchedTaxon"."matchedTaxonConfidence_fraction" FROM "MatchedTaxon" WHERE score_ok("MatchedTaxon"."matchedTaxonConfidence_fraction");
222

  
223

  
224
--
225
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
226
--
227

  
228
COMMENT ON VIEW "ValidMatchedTaxon" IS 'to update, use * as the column list';
229

  
230

  
231
--
232
-- Name: ScrubbedTaxon; Type: VIEW; Schema: TNRS; Owner: -
233
--
234

  
235
CREATE VIEW "ScrubbedTaxon" AS
236
    SELECT "ValidMatchedTaxon"."acceptedScientificName", "ValidMatchedTaxon"."*Name_matched.batch", "ValidMatchedTaxon"."concatenatedScientificName", "ValidMatchedTaxon"."matchedTaxonName", "ValidMatchedTaxon"."matchedTaxonRank", "ValidMatchedTaxon"."*Name_matched.Name_score", "ValidMatchedTaxon"."matchedScientificNameAuthorship", "ValidMatchedTaxon"."matchedScientificNameID", "ValidMatchedTaxon"."*Name_matched.Author_score", "ValidMatchedTaxon"."matchedFamilyConfidence_fraction", "ValidMatchedTaxon"."matchedFamily", "ValidMatchedTaxon"."matchedGenus", "ValidMatchedTaxon"."matchedGenusConfidence_fraction", "ValidMatchedTaxon"."matchedSpecificEpithet", "ValidMatchedTaxon"."matchedSpeciesConfidence_fraction", "ValidMatchedTaxon"."matchedInfraspecificEpithet", "ValidMatchedTaxon"."*Name_matched.Infraspecific_epithet_score", "ValidMatchedTaxon"."identificationQualifier", "ValidMatchedTaxon"."morphospeciesSuffix", "ValidMatchedTaxon"."taxonomicStatus", "ValidMatchedTaxon"."acceptedTaxonName", "ValidMatchedTaxon"."acceptedScientificNameAuthorship", "ValidMatchedTaxon"."acceptedTaxonRank", "ValidMatchedTaxon"."acceptedScientificNameID", "ValidMatchedTaxon"."*Name_matched.Accepted_name_species", "ValidMatchedTaxon"."acceptedFamily", "ValidMatchedTaxon"."*Name_matched.Selected", "ValidMatchedTaxon"."*Name_matched.Source", "ValidMatchedTaxon"."*Name_matched.Warnings", "ValidMatchedTaxon"."*Name_matched.Accepted_name_lsid", "ValidMatchedTaxon"."matchedTaxonConfidence_fraction", "AcceptedTaxon"."*Accepted_name.batch", "AcceptedTaxon"."acceptedGenus", "AcceptedTaxon"."acceptedSpecificEpithet", "AcceptedTaxon"."acceptedInfraspecificEpithet", "AcceptedTaxon"."acceptedTaxonomicStatus", "AcceptedTaxon"."*Accepted_name.Selected", "AcceptedTaxon"."*Accepted_name.Source", "AcceptedTaxon"."*Accepted_name.Warnings", "AcceptedTaxon"."*Accepted_name.Accepted_name_lsid" FROM ("ValidMatchedTaxon" NATURAL LEFT JOIN "AcceptedTaxon");
237

  
238

  
239
--
240
-- Name: VIEW "ScrubbedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
241
--
242

  
243
COMMENT ON VIEW "ScrubbedTaxon" IS 'to update, use * as the column list';
244

  
245

  
246
--
247
-- Name: Source; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
248
--
249

  
250
CREATE TABLE "Source" (
251
    "*row_num" integer NOT NULL,
252
    "sourceType" text DEFAULT 'aggregator'::text NOT NULL,
253
    "datasetURL" text DEFAULT 'http://tnrs.iplantcollaborative.org/TNRSapp.html'::text NOT NULL
254
);
255

  
256

  
257
--
258
-- Name: COLUMN "Source"."sourceType"; Type: COMMENT; Schema: TNRS; Owner: -
259
--
260

  
261
COMMENT ON COLUMN "Source"."sourceType" IS 'constant';
262

  
263

  
264
--
265
-- Name: COLUMN "Source"."datasetURL"; Type: COMMENT; Schema: TNRS; Owner: -
266
--
267

  
268
COMMENT ON COLUMN "Source"."datasetURL" IS 'constant';
269

  
270

  
271
--
272
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
273
--
274

  
275
CREATE TABLE batch (
276
    id text NOT NULL,
277
    id_by_time text,
278
    time_submitted timestamp with time zone DEFAULT now(),
279
    client_version text
280
);
281

  
282

  
283
--
284
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
285
--
286

  
287
CREATE TABLE batch_download_settings (
288
    id text NOT NULL,
289
    "E-mail" text,
290
    "Id" text,
291
    "Job type" text,
292
    "Contains Id" boolean,
293
    "Start time" text,
294
    "Finish time" text,
295
    "TNRS version" text,
296
    "Sources selected" text,
297
    "Match threshold" double precision,
298
    "Classification" text,
299
    "Allow partial matches?" boolean,
300
    "Sort by source" boolean,
301
    "Constrain by higher taxonomy" boolean
302
);
303

  
304

  
305
--
306
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
307
--
308

  
309
COMMENT ON TABLE batch_download_settings IS 'stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt';
310

  
311

  
312
--
313
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
314
--
315

  
316
CREATE TABLE client_version (
317
    id text NOT NULL,
318
    global_rev integer NOT NULL,
319
    "/lib/tnrs.py rev" integer,
320
    "/bin/tnrs_db rev" integer
321
);
322

  
323

  
324
--
325
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
326
--
327

  
328
COMMENT ON TABLE client_version IS 'contains svn revisions';
329

  
330

  
331
--
332
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
333
--
334

  
335
COMMENT ON COLUMN client_version.global_rev IS 'from `svn info .` > Last Changed Rev';
336

  
337

  
338
--
339
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
340
--
341

  
342
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS 'from `svn info lib/tnrs.py` > Last Changed Rev';
343

  
344

  
345
--
346
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
347
--
348

  
349
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS 'from `svn info bin/tnrs_db` > Last Changed Rev';
350

  
351

  
352
--
353
-- Name: ~Source.map; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
354
--
355

  
356
CREATE TABLE "~Source.map" (
357
    "from" text NOT NULL,
358
    "to" text,
359
    filter text,
360
    notes text
361
);
362

  
363

  
364
--
365
-- Name: Source_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
366
--
367

  
368
ALTER TABLE ONLY "Source"
369
    ADD CONSTRAINT "Source_pkey" PRIMARY KEY ("*row_num");
370

  
371

  
372
--
373
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
374
--
375

  
376
ALTER TABLE ONLY batch_download_settings
377
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
378

  
379

  
380
--
381
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
382
--
383

  
384
ALTER TABLE ONLY batch
385
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
386

  
387

  
388
--
389
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
390
--
391

  
392
ALTER TABLE ONLY batch
393
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
394

  
395

  
396
--
397
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
398
--
399

  
400
ALTER TABLE ONLY client_version
401
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
402

  
403

  
404
--
405
-- Name: tnrs_Name_submitted_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
406
--
407

  
408
ALTER TABLE ONLY tnrs
409
    ADD CONSTRAINT "tnrs_Name_submitted_key" UNIQUE ("Name_submitted");
410

  
411

  
412
--
413
-- Name: tnrs_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
414
--
415

  
416
ALTER TABLE ONLY tnrs
417
    ADD CONSTRAINT tnrs_pkey PRIMARY KEY (batch, "Name_number");
418

  
419

  
420
--
421
-- Name: ~Source.map_from_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
422
--
423

  
424
ALTER TABLE ONLY "~Source.map"
425
    ADD CONSTRAINT "~Source.map_from_key" UNIQUE ("from");
426

  
427

  
428
--
429
-- Name: ~Source.map_to_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
430
--
431

  
432
ALTER TABLE ONLY "~Source.map"
433
    ADD CONSTRAINT "~Source.map_to_key" UNIQUE ("to");
434

  
435

  
436
--
437
-- Name: tnrs_score_ok; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
438
--
439

  
440
CREATE UNIQUE INDEX tnrs_score_ok ON tnrs USING btree ("Name_submitted") WHERE score_ok("Max_score");
441

  
442

  
443
--
444
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
445
--
446

  
447
CREATE TRIGGER batch__fill BEFORE INSERT OR UPDATE ON batch FOR EACH ROW EXECUTE PROCEDURE batch__fill();
448

  
449

  
450
--
451
-- Name: map_filter_insert; Type: TRIGGER; Schema: TNRS; Owner: -
452
--
453

  
454
CREATE TRIGGER map_filter_insert BEFORE INSERT ON "~Source.map" FOR EACH ROW EXECUTE PROCEDURE util.map_filter_insert();
455

  
456
ALTER TABLE "~Source.map" DISABLE TRIGGER map_filter_insert;
457

  
458

  
459
--
460
-- Name: tnrs_populate_fields; Type: TRIGGER; Schema: TNRS; Owner: -
461
--
462

  
463
CREATE TRIGGER tnrs_populate_fields BEFORE INSERT OR UPDATE ON tnrs FOR EACH ROW EXECUTE PROCEDURE tnrs_populate_fields();
464

  
465

  
466
--
467
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
468
--
469

  
470
ALTER TABLE ONLY batch
471
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
472

  
473

  
474
--
475
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
476
--
477

  
478
ALTER TABLE ONLY batch_download_settings
479
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
480

  
481

  
482
--
483
-- Name: tnrs_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
484
--
485

  
486
ALTER TABLE ONLY tnrs
487
    ADD CONSTRAINT tnrs_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
488

  
489

  
490
--
491
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
492
--
493

  
494
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
495
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
496
GRANT ALL ON SCHEMA "TNRS" TO bien;
497
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
498

  
499

  
500
--
501
-- Name: tnrs; Type: ACL; Schema: TNRS; Owner: -
502
--
503

  
504
REVOKE ALL ON TABLE tnrs FROM PUBLIC;
505
REVOKE ALL ON TABLE tnrs FROM bien;
506
GRANT ALL ON TABLE tnrs TO bien;
507
GRANT SELECT ON TABLE tnrs TO bien_read;
508

  
509

  
510
--
511
-- PostgreSQL database dump complete
512
--
513

  

Also available in: Unified diff