Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Detect templates with duplicated items
    SELECT "ID" as tempalte_id, "IMPORT_TYPE", "NAME" as template_name, "CHECKLIST_ID" as "CHECKLIST_ID" FROM "AO_C2A220_TEMPLATE" acat
    WHERE "CHECKLIST_ID" IN (
    SELECT sub."CHECKLIST_ID"
    FROM ( SELECT "CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
    FROM "AO_C2A220_ITEM" acai
    GROUP BY "CHECKLIST_ID", "VALUE"
    ) AS sub
    GROUP BY sub."CHECKLIST_ID"
    HAVING COUNT(sub."VALUE") = SUM(sub.count_values) / 2 );

  2. Delete item details. The checklist ids can be found in the result of the first query.
    delete from "AO_C2A220_QUOTE" where "ITEM_ID" in (
    select min from( SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
    FROM "AO_C2A220_ITEM" acai
    GROUP BY "CHECKLIST_ID", "VALUE"
    having COUNT("VALUE") > 1
    -- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
    ) ;
    where for "CHECKLIST_ID" = 11 replace 11 with the value from the first query

  3. Delete item assignee. The checklist ids can be found in the result of the first query.
    delete from "AO_C2A220_ASSIGNEE" where "ITEM_ID" in (
    select min from( SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
    FROM "AO_C2A220_ITEM" acai
    GROUP BY "CHECKLIST_ID", "VALUE"
    having COUNT("VALUE") > 1
    -- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
    ) ;
    where for "CHECKLIST_ID" = 11 replace 11 with the value from the first query

  4. Status
    colourYellow
    titleOptional
    Delete linked items - needed only for Linked templates that are imported to the issues (IMPORT_TYPE - LINKED). The checklist ids can be found in the result of the first query.
    delete from "AO_C2A220_LINKED_ITEM" where "ITEM_ID" in (
    select min from( SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
    FROM "AO_C2A220_ITEM" acai
    GROUP BY "CHECKLIST_ID", "VALUE"
    having COUNT("VALUE") > 1
    -- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
    ) ;
    where for "CHECKLIST_ID" = 11 replace 11 with the value from the first query

  5. Delete duplicate items. The checklist ids can be found in the result of the first query.
    delete from "AO_C2A220_ITEM" where "ID" IN(
    select min from(
    SELECT MIN("ID"),"CHECKLIST_ID", "VALUE", COUNT("VALUE") AS count_values
    FROM "AO_C2A220_ITEM" acai
    GROUP BY "CHECKLIST_ID", "VALUE"
    having COUNT("VALUE") > 1
    -- and "CHECKLIST_ID" = 11 -- ADD THIS CONDITION ALSO TO delete checklist by checklist, not all at once ) as abc
    );
    where for "CHECKLIST_ID" = 11 replace 11 with the value from the first query

  6. Repeat steps 2, 3, and 4 (using "CHECKLIST_ID" = your value) as many times as there were templates found in the first query

...