Skip to content

Commit aa7efa8

Browse files
committed
Merge branch 'release-0.9.3'
2 parents 37a384e + 2b732c9 commit aa7efa8

File tree

4 files changed

+203
-0
lines changed

4 files changed

+203
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddCitesListingToApiTaxonConceptsView < ActiveRecord::Migration
2+
def change
3+
execute "DROP VIEW IF EXISTS api_taxon_concepts_view"
4+
execute "CREATE VIEW api_taxon_concepts_view AS #{view_sql('20150116112256', 'api_taxon_concepts_view')}"
5+
end
6+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CheckForSynonymStatusInApiTaxonConceptsView < ActiveRecord::Migration
2+
def up
3+
execute "DROP VIEW IF EXISTS api_taxon_concepts_view"
4+
execute "CREATE VIEW api_taxon_concepts_view AS #{view_sql('20150119122122', 'api_taxon_concepts_view')}"
5+
end
6+
7+
def down
8+
execute "DROP VIEW IF EXISTS api_taxon_concepts_view"
9+
execute "CREATE VIEW api_taxon_concepts_view AS #{view_sql('20150116112256', 'api_taxon_concepts_view')}"
10+
end
11+
end
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
SELECT
2+
tc.id,
3+
tc.parent_id,
4+
taxonomies.name,
5+
CASE WHEN taxonomies.name = 'CITES_EU' THEN TRUE ELSE FALSE END AS taxonomy_is_cites_eu,
6+
tc.full_name,
7+
tc.author_year,
8+
'A' AS name_status,
9+
ranks.name AS rank,
10+
tc.taxonomic_position,
11+
tc.listing->'cites_listing' AS cites_listing,
12+
tc.data->'kingdom_name' AS kingdom_name,
13+
tc.data->'phylum_name' AS phylum_name,
14+
tc.data->'class_name' AS class_name,
15+
tc.data->'order_name' AS order_name,
16+
tc.data->'family_name' AS family_name,
17+
tc.data->'genus_name' AS genus_name,
18+
ROW_TO_JSON(
19+
ROW(
20+
tc.data->'kingdom_name',
21+
tc.data->'phylum_name',
22+
tc.data->'class_name',
23+
tc.data->'order_name',
24+
tc.data->'family_name'
25+
)::api_higher_taxa
26+
) AS higher_taxa,
27+
ARRAY_TO_JSON(
28+
ARRAY_AGG_NOTNULL(
29+
ROW(
30+
synonyms.id, synonyms.full_name, synonyms.author_year, synonyms.data->'rank_name'
31+
)::api_taxon_concept
32+
)
33+
) AS synonyms,
34+
NULL AS accepted_names,
35+
tc.created_at,
36+
tc.updated_at
37+
FROM taxon_concepts tc
38+
JOIN taxonomies ON taxonomies.id = tc.taxonomy_id
39+
JOIN ranks ON ranks.id = tc.rank_id
40+
LEFT JOIN taxon_relationships tr
41+
ON tr.taxon_concept_id = tc.id
42+
LEFT JOIN taxon_relationship_types trt
43+
ON trt.id = tr.taxon_relationship_type_id AND trt.name = 'HAS_SYNONYM'
44+
LEFT JOIN taxon_concepts synonyms
45+
ON synonyms.id = tr.other_taxon_concept_id
46+
WHERE tc.name_status = 'A'
47+
GROUP BY tc.id, tc.parent_id, taxonomies.name, tc.full_name, tc.author_year, ranks.name,
48+
tc.taxonomic_position,
49+
tc.created_at, tc.updated_at
50+
51+
UNION ALL
52+
53+
SELECT
54+
tc.id,
55+
NULL AS parent_id,
56+
taxonomies.name,
57+
CASE WHEN taxonomies.name = 'CITES' THEN TRUE ELSE FALSE END AS taxonomy_is_cites_eu,
58+
tc.full_name,
59+
tc.author_year,
60+
'S' AS name_status,
61+
ranks.name AS rank,
62+
NULL AS taxonomic_position,
63+
NULL AS cites_listing,
64+
NULL AS kingdom_name,
65+
NULL AS phylum_name,
66+
NULL AS class_name,
67+
NULL AS order_name,
68+
NULL AS family_name,
69+
NULL AS genus_name,
70+
NULL::JSON AS higher_taxa,
71+
NULL AS synonyms,
72+
ARRAY_TO_JSON(
73+
ARRAY_AGG_NOTNULL(
74+
ROW(
75+
accepted_names.id, accepted_names.full_name, accepted_names.author_year, accepted_names.data->'rank_name'
76+
)::api_taxon_concept
77+
)
78+
) AS accepted_names,
79+
tc.created_at,
80+
tc.updated_at
81+
FROM taxon_concepts tc
82+
JOIN taxonomies ON taxonomies.id = tc.taxonomy_id
83+
JOIN ranks ON ranks.id = tc.rank_id
84+
JOIN taxon_relationships tr
85+
ON tr.other_taxon_concept_id = tc.id
86+
JOIN taxon_relationship_types trt
87+
ON trt.id = tr.taxon_relationship_type_id AND trt.name = 'HAS_SYNONYM'
88+
JOIN taxon_concepts accepted_names
89+
ON accepted_names.id = tr.taxon_concept_id
90+
WHERE tc.name_status = 'S'
91+
GROUP BY tc.id, tc.parent_id, taxonomies.name, tc.full_name, tc.author_year, ranks.name,
92+
tc.taxonomic_position,
93+
tc.created_at, tc.updated_at;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
SELECT
2+
tc.id,
3+
tc.parent_id,
4+
taxonomies.name,
5+
CASE WHEN taxonomies.name = 'CITES_EU' THEN TRUE ELSE FALSE END AS taxonomy_is_cites_eu,
6+
tc.full_name,
7+
tc.author_year,
8+
'A' AS name_status,
9+
ranks.name AS rank,
10+
tc.taxonomic_position,
11+
tc.listing->'cites_listing' AS cites_listing,
12+
tc.data->'kingdom_name' AS kingdom_name,
13+
tc.data->'phylum_name' AS phylum_name,
14+
tc.data->'class_name' AS class_name,
15+
tc.data->'order_name' AS order_name,
16+
tc.data->'family_name' AS family_name,
17+
tc.data->'genus_name' AS genus_name,
18+
ROW_TO_JSON(
19+
ROW(
20+
tc.data->'kingdom_name',
21+
tc.data->'phylum_name',
22+
tc.data->'class_name',
23+
tc.data->'order_name',
24+
tc.data->'family_name'
25+
)::api_higher_taxa
26+
) AS higher_taxa,
27+
ARRAY_TO_JSON(
28+
ARRAY_AGG_NOTNULL(
29+
ROW(
30+
synonyms.id, synonyms.full_name, synonyms.author_year, synonyms.data->'rank_name'
31+
)::api_taxon_concept
32+
)
33+
) AS synonyms,
34+
NULL AS accepted_names,
35+
tc.created_at,
36+
tc.updated_at
37+
FROM taxon_concepts tc
38+
JOIN taxonomies ON taxonomies.id = tc.taxonomy_id
39+
JOIN ranks ON ranks.id = tc.rank_id
40+
LEFT JOIN taxon_relationships tr
41+
ON tr.taxon_concept_id = tc.id
42+
LEFT JOIN taxon_relationship_types trt
43+
ON trt.id = tr.taxon_relationship_type_id AND trt.name = 'HAS_SYNONYM'
44+
LEFT JOIN taxon_concepts synonyms
45+
ON synonyms.id = tr.other_taxon_concept_id AND synonyms.taxonomy_id = taxonomies.id
46+
WHERE tc.name_status = 'A'
47+
GROUP BY tc.id, tc.parent_id, taxonomies.name, tc.full_name, tc.author_year, ranks.name,
48+
tc.taxonomic_position,
49+
tc.created_at, tc.updated_at
50+
51+
UNION ALL
52+
53+
SELECT
54+
tc.id,
55+
NULL AS parent_id,
56+
taxonomies.name,
57+
CASE WHEN taxonomies.name = 'CITES' THEN TRUE ELSE FALSE END AS taxonomy_is_cites_eu,
58+
tc.full_name,
59+
tc.author_year,
60+
'S' AS name_status,
61+
ranks.name AS rank,
62+
NULL AS taxonomic_position,
63+
NULL AS cites_listing,
64+
NULL AS kingdom_name,
65+
NULL AS phylum_name,
66+
NULL AS class_name,
67+
NULL AS order_name,
68+
NULL AS family_name,
69+
NULL AS genus_name,
70+
NULL::JSON AS higher_taxa,
71+
NULL AS synonyms,
72+
ARRAY_TO_JSON(
73+
ARRAY_AGG_NOTNULL(
74+
ROW(
75+
accepted_names.id, accepted_names.full_name, accepted_names.author_year, accepted_names.data->'rank_name'
76+
)::api_taxon_concept
77+
)
78+
) AS accepted_names,
79+
tc.created_at,
80+
tc.updated_at
81+
FROM taxon_concepts tc
82+
JOIN taxonomies ON taxonomies.id = tc.taxonomy_id
83+
JOIN ranks ON ranks.id = tc.rank_id
84+
JOIN taxon_relationships tr
85+
ON tr.other_taxon_concept_id = tc.id
86+
JOIN taxon_relationship_types trt
87+
ON trt.id = tr.taxon_relationship_type_id AND trt.name = 'HAS_SYNONYM'
88+
JOIN taxon_concepts accepted_names
89+
ON accepted_names.id = tr.taxon_concept_id AND accepted_names.taxonomy_id = taxonomies.id
90+
WHERE tc.name_status = 'S'
91+
GROUP BY tc.id, tc.parent_id, taxonomies.name, tc.full_name, tc.author_year, ranks.name,
92+
tc.taxonomic_position,
93+
tc.created_at, tc.updated_at;

0 commit comments

Comments
 (0)