Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix SQL

...

Here is some SQL that does the job, including fixing the issuelinktype  if you hadn't already done so above.

Code Block
-- https://www.redradishtech.com/pages/viewpage.action?pageId=14483457
begin;
create temp sequence issuelink_seq start with 99999; -- https://stackoverflow.com/questions/37057643/postgresql-starting-a-sequence-at-maxthe-column1                                                                                        
select setval('issuelink_seq', (select max(id::bigint)+1 from issuelink));
WITH jpolinks AS (
	    select entity_id AS child_id, (json_value::json->>'parent_id')::numeric AS parent_id from entity_property where entity_name='IssueProperty' and property_key='jpo-issue-properties')                                                     
, newissuelinks AS (
  select nextval('issuelink_seq') AS id
		        , jpolinktype.id AS linktype
		        , parent_id AS source
		        , child_id as destination
		        ,  null::numeric AS sequence
  from jpolinks
    CROSS JOIN (select id from issuelinktype where linkname='Parent-Child Link') jpolinktype
  where parent_id is not null -- the parent_id JSON is sometimes empty
    and not exists (select * From issuelink where source=parent_id and destination=child_id and issuelinktypelinktype=jpolinktype.id) -- don't double-insert                                                                                              
)
insert into issuelink select * from newissuelinks;
update sequence_value_item set seq_id=nextval('issuelink_seq') where seq_name='IssueLink';
update issuelinktype set pstyle=null where pstyle='jira_jpos_parent_child'; 
commit;

After running the above, you will have to restart Jira for the changes to take effect.

...