SQL equivalents for Jira server's workflow integrity checks
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the server and data center platforms.
You may also be interested in:
Symptoms
The workflow integrity checker is timing out when running in the browser, preventing it from running.
Cause
The instance is of a significant size and checks are not able to complete within the timeout period. We have a suggestion to fix this with a progress bar as tracked in - JRA-17593Getting issue details... STATUS .
Workaround
The SQL checks for workflows can be done by manually executing them against the database.
Always back up your data before performing any modification to the database. If possible, try your modifications on a test server.
All queries were written and tested on PostgreSQL. Other DB products might need syntax adjustments and your setup might require database name and schema to be provided for table names.
If your database is case sensitive, and any query returns an error related to table not found, please observe if in the database the queried table name is capitalized or in lower case.
Workflow entry states are correct
This will check for any workflows that have an invalid state, as a result of - JRA-4241Getting issue details... STATUS .
SELECT jiraissue.id issue_id, jiraissue.workflow_id, os_wfentry.* FROM jiraissue JOIN os_wfentry ON jiraissue.workflow_id = os_wfentry.id WHERE os_wfentry.state IS NULL OR os_wfentry.state = 0;
If this returns any records, for example below, they will need to be updated to be valid:
issue_id | workflow_id | id | name | initialized | state ----------+-------------+-------+------------------------------+-------------+------- 10023 | 10023 | 10023 | jdg-workflow-2-1377070570282 | | 0
To fix this example, run the following SQL - we need to update the
state
to be 1 based on theworkflow_id
. Theworkflow_id
is actuallyos_wfentry.id
UPDATE os_wfentry SET state = 1 WHERE id IN (SELECT os_wfentry.id FROM jiraissue JOIN os_wfentry ON jiraissue.workflow_id = os_wfentry.id WHERE os_wfentry.state IS NULL OR os_wfentry.state = 0);
Jira Issues with Null Status
This will check if any issues have an invalid issue status, as from - JRA-7428Getting issue details... STATUS :
SELECT jiraissue.id, jiraissue.issuenum, jiraissue.issuestatus, jiraissue.project, jiraissue.issuetype, currentStep.step_id FROM jiraissue JOIN os_currentstep currentStep ON jiraissue.workflow_id = currentStep.entry_id WHERE jiraissue.issuestatus IS NULL;
And can be fixed with the following:
UPDATE jiraissue SET issuestatus = (SELECT state FROM os_wfentry WHERE id = workflow_id) WHERE issuestatus IS NULL;
Workflow current step entries
This will check if any issues have an invalid workflow id, as from - JRASERVER-4539Getting issue details... STATUS :
select concat(concat(P.pkey,'-'),I.issuenum) from jiraissue I join project P on P.id = I.project left join os_currentstep C on C.entry_id = I.workflow_id where C.id is null;
Running the query below will generate the inserts for all issues missing the valid workflow step entry:
select concat(concat('insert into os_currentstep values ((select max(id)+1 from os_currentstep),',workflow_id),',1,0,'''',now(),null,null,''open'',null)') from jiraissue where not exists (select * from os_currentstep where entry_id=workflow_id);
- Copy all results and run the inserts to add the missing rows.