Skip to content

Prevent duplicates#39

Open
rimi-itk wants to merge 4 commits intodevelopfrom
feature/prevent-duplicates
Open

Prevent duplicates#39
rimi-itk wants to merge 4 commits intodevelopfrom
feature/prevent-duplicates

Conversation

@rimi-itk
Copy link
Copy Markdown
Contributor

@rimi-itk rimi-itk commented Apr 10, 2026

Link to ticket

https://leantime.itkdev.dk/_#/tickets/showTicket/7131

Description

When importing systems and reports, we currently duplicate inactive items. This is due to EntityActiveFilter filtering out all inactive entities and thus the importer does not detect if an inactive items already exists (and creates a duplicate).

We resolve this by

  • Disabling the doctrine filter in data importers

As added bonusses we also clean up a bit by

  • Nullifying empty dates; they're currently set to “now”
  • Cleaning up

We need to clean up the current data, and one way to do this (and probably also the best and most correct) is to delete all but the first row of any group of duplicated rows (sharing a sys_internal_id). This can be done by observing that the first row in a group is the one with the lowest ID (AUTO_INCREMENT actually increments values!), and then using the following SQL incantations to clean up:

DELETE t1
FROM report t1 INNER JOIN report t2
WHERE t1.sys_internal_id = t2.sys_internal_id AND t1.id > t2.id;

DELETE t1
FROM system t1 INNER JOIN system t2
WHERE t1.sys_internal_id = t2.sys_internal_id AND t1.id > t2.id;

Shout out to https://stackoverflow.com/a/79695983 for coming up with this!

@rimi-itk rimi-itk force-pushed the feature/prevent-duplicates branch from eb185fc to 33e94c5 Compare April 10, 2026 14:43
@rimi-itk rimi-itk marked this pull request as ready for review April 10, 2026 14:48
@rimi-itk rimi-itk requested review from cableman, martinyde and tuj April 10, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants