Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a migration to fix tree structure issues due to an old WorkBench bug #5131

Open
grantfitzsimmons opened this issue Jul 23, 2024 · 0 comments · May be fixed by #5366
Open

Create a migration to fix tree structure issues due to an old WorkBench bug #5131

grantfitzsimmons opened this issue Jul 23, 2024 · 0 comments · May be fixed by #5366
Assignees
Labels
1 - Enhancement Improvements or extensions to existing behavior 2 - Database/Schema Issues that are related to the underlying database and schema
Milestone

Comments

@grantfitzsimmons
Copy link
Member

grantfitzsimmons commented Jul 23, 2024

Is your feature request related to a problem? Please describe.
Since the release of the WorkBench (v7.6.1) until sometime around the release of Specify v7.9.0, taxon records uploaded via the WorkBench did not have isAccepted as true by default.

This results in a "Bad tree structure" error, preventing children from being added to any node (or any descendent of any node) that has IsAccepted as false yet still is not a synonym.

image

The underlying issue is not apparent to the user nor to some troubleshooting this.

Describe the solution you'd like
We should automatically fix all such cases.

You can return erroneous not accepted Taxon records here:

SELECT t1.TaxonID 
FROM taxon t1 
LEFT JOIN taxon t2 ON t1.AcceptedID = t2.TaxonID 
WHERE t1.IsAccepted = 0 AND t2.TaxonID IS NULL

This SQL query performs the following operations:

  1. SELECT t1.TaxonID: This part of the query selects the TaxonID column from the taxon table, which is aliased as t1.

  2. FROM taxon t1: This part of the query specifies the taxon table as the primary table, and assigns the alias t1 to it.

  3. LEFT JOIN taxon t2 ON t1.AcceptedID = t2.TaxonID: This part of the query performs a left join between the taxon table (aliased as t1) and the taxon table (aliased as t2). The join condition is that the AcceptedID column in t1 must match the TaxonID column in t2.

  4. WHERE t1.IsAccepted = 0 AND t2.TaxonID IS NULL: This part of the query applies a filter to the result set. It selects only the rows where:

    • t1.IsAccepted is 0 (i.e., the taxon is not accepted)
    • t2.TaxonID is NULL (i.e., there is no matching accepted taxon in the t2 table)

This essentially retrieves the TaxonID values for all taxa that are not accepted, and for which there is no corresponding accepted taxon in the database. This should only include problem taxa.

To fix cases like this, we can simply run:

UPDATE taxon 
SET IsAccepted = TRUE 
WHERE TaxonID IN (
    SELECT t1.TaxonID 
    FROM taxon t1 
    LEFT JOIN taxon t2 ON t1.AcceptedID = t2.TaxonID 
    WHERE t1.IsAccepted = 0 AND t2.TaxonID IS NULL
);

but it seems like a good candidate for a migration so that this is handled on all databases once since the issue is most likely widespread and present on self-hosted institution databases as well.

@grantfitzsimmons grantfitzsimmons added 1 - Request A request made by a member of the community 2 - Database/Schema Issues that are related to the underlying database and schema labels Jul 23, 2024
@grantfitzsimmons grantfitzsimmons changed the title Create a migration to fix tree structure issues due to an old bug Create a migration to fix tree structure issues due to an old WorkBench bug Jul 23, 2024
@grantfitzsimmons grantfitzsimmons added this to the 7.9.x milestone Aug 2, 2024
@grantfitzsimmons grantfitzsimmons self-assigned this Nov 1, 2024
grantfitzsimmons added a commit that referenced this issue Nov 1, 2024
@grantfitzsimmons grantfitzsimmons added 1 - Enhancement Improvements or extensions to existing behavior and removed 1 - Request A request made by a member of the community labels Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - Enhancement Improvements or extensions to existing behavior 2 - Database/Schema Issues that are related to the underlying database and schema
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant