Skip to content

DB migration to unassign deleted tags#812

Merged
HaGuesto merged 5 commits into
masterfrom
db-migration-unassign-deleted-tags
May 20, 2026
Merged

DB migration to unassign deleted tags#812
HaGuesto merged 5 commits into
masterfrom
db-migration-unassign-deleted-tags

Conversation

@pylipp
Copy link
Copy Markdown
Contributor

@pylipp pylipp commented Jan 23, 2026

https://trello.com/c/fYH0ezlH

Testing:

  • start DB
  • list active tags_relations with deleted tags (should be 0):
select count(1) from tags_relations tr
inner join tags t
on t.id = tr.tag_id
where ((tr.deleted_on is NULL) and (t.deleted > 0))
  • soft-delete some tags: update tags set deleted = NOW() where id in (45, 47);
  • list active tags_relations with deleted tags again (should be 75 rows)
  • run the migration. Should print "Updated rows: 75"
  • list active tags_relations with deleted tags again (should be 0 rows)
  • compare deleted fields (should be the same):
select deleted from tags where id in (45, 47);
select deleted_on from tags_relations where tag_id in (45, 47);

I set tr.deleted_by_id = 1 because I find it inconsistent to have tags_relations rows with non-NULL deleted_on but NULL deleted_by_id.

@pylipp pylipp force-pushed the db-migration-unassign-deleted-tags branch from 886110d to 82b1861 Compare April 20, 2026 06:52
@pylipp pylipp marked this pull request as ready for review April 20, 2026 06:52
@pylipp pylipp requested a review from Copilot May 20, 2026 14:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Phinx database migration to automatically “unassign” (soft-delete) any tags_relations rows that are still active (deleted_on IS NULL) but reference tags that have been soft-deleted, keeping tag assignments consistent after tag deletion.

Changes:

  • Introduces a new migration that updates tags_relations.deleted_on (and deleted_by_id) based on tags.deleted.
  • Logs the number of affected rows to the migration output.

Comment thread db/migrations/20260123123229_unassign_deleted_tags.php Outdated
Comment thread db/migrations/20260123123229_unassign_deleted_tags.php
Comment thread db/migrations/20260123123229_unassign_deleted_tags.php Outdated
@HaGuesto HaGuesto merged commit ad05a22 into master May 20, 2026
6 checks passed
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.

3 participants