gaiaresources / ala-citizenscience

Automatically exported from code.google.com/p/ala-citizenscience
1 stars 4 forks source link

Record uploads via the ApplicationService create multiple 'Field Species' taxon groups #361

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Instead, we should keep reusing the same taxon group with the name 'Field 
Species'

Original issue reported on code.google.com by aaron.lo...@gmail.com on 25 Oct 2012 at 6:40

GoogleCodeExporter commented 9 years ago
The problem is caused by a race when.

1. no Field Species has been created yet
2. The application service is hit multiple times in quick succession.

This causes the lazy created Field species object to be created several times 
due to the transactional nature of each request.

Fix by creating a Field Species with Taxon group etc at portal creation time.

Original comment by aaron.lo...@gmail.com on 31 Oct 2012 at 1:53

GoogleCodeExporter commented 9 years ago
The fix has been made for new portals. If this problem comes up on old portals 
use the following SQL with the appropriate changes to the taxon group id to 
keep and the indicator species id to keep.

As always, run in a transaction!

begin;

-- keep taxon_group_id = 3
select taxon_group_id into temp taxon_group_to_delete from taxon_group where 
name='Field Names' and taxon_group_id != 3;
select attributes_attribute_id into temp attr_to_delete from 
taxon_group_attribute where taxon_group_taxon_group_id in (select 
taxon_group_id from taxon_group_to_delete);

update indicator_species set taxon_group_id=3 where taxon_group_id in (select 
taxon_group_id from taxon_group_to_delete);

update attribute_value set attribute_id=(select attributes_attribute_id from 
taxon_group_attribute where taxon_group_taxon_group_id=3) where attribute_id in 
(select attributes_attribute_id from attr_to_delete);

delete from taxon_group_attribute where taxon_group_taxon_group_id in (select 
taxon_group_id from taxon_group_to_delete);
delete from attribute where attribute_id in (select attributes_attribute_id 
from attr_to_delete);
delete from taxon_group where taxon_group_id in (select taxon_group_id from 
taxon_group_to_delete);

-- keep indicator_species_id = 119
select indicator_species_id as id into temp species_to_delete from 
indicator_species where scientific_name = 'Field Species' and 
indicator_species_id != 119;
update record set indicator_species_id = 119 where indicator_species_id in 
(select id from species_to_delete);
delete from indicator_species where indicator_species_id in (select id from 
species_to_delete);

Original comment by aaron.lo...@gmail.com on 2 Nov 2012 at 2:52

GoogleCodeExporter commented 9 years ago

Original comment by aaron.lo...@gmail.com on 2 Nov 2012 at 2:52