Repository navigation
fix(core): remove byline credits when content is permanently deleted - #3158
Conversation
Byline credits are stored per entry row in `_emdash_content_bylines`, with no foreign key to the content table. Permanently deleting an entry removes its row, SEO data, comments and revisions, but not its credits. Against the current handler, a purged entry's credit rows stay behind, on SQLite and PostgreSQL. Two cases pin what the purge must leave alone: another translation's credits, and the credits of an entry with the same id in another collection. A fourth shows where the leftovers surface: a seed that re-creates a slugless entry under its seed ID, with no credits of its own, comes back with the purged entry's credits.
Credits belong to a single entry row: saving an entry writes rows for its own id, and a new translation gets copies under its own id. Permanent delete never removed them, so they outlived the entry. The handler now deletes the purged row's credits next to the SEO, comment and revision cleanup. Unlike term assignments, no check for surviving translations applies, since no other row reads these credits. Credits left behind by earlier deletes stay.
🦋 Changeset detectedLatest commit: 3230f09 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
This is the right fix for the reported orphan-credit problem, implemented in the right place. Permanent delete already cleans up SEO, comments, and revisions; byline credits are another per-entry dependent row and belong in the same transaction. By deleting them inside handleContentPermanentDelete before commit, the seed re-apply case described in #1683 is fixed going forward without changing seed behavior.
I checked:
- The handler change is inside the existing transaction and only runs when the row was actually deleted.
BylineRepository.deleteContentBylinesuses the existing junction index (idx_content_bylines_content) and follows the same safe, parameterized Kysely patterns as siblingdeleteByContent/deleteByEntrymethods.- The per-entry cleanup is correctly not shared across translations or across collections, consistent with the column-key design of
_emdash_content_bylines. - The regression test covers the bug, translation isolation, collection isolation, and the seed re-apply scenario on both SQLite and PostgreSQL.
- The changeset is accurate and user-facing.
No blockers or convention violations. The PR is clean.
What does this PR do?
Removes an entry's byline credits when the entry is permanently deleted.
Credits are stored per entry row with no foreign key, and permanent delete never removed them, so they outlived the entry. The handler now deletes the purged row's credits alongside the SEO, comment and revision cleanup. Each translation has its own credit rows, so unlike the term assignments in #3091 no check for remaining translations is needed, and the other translations keep their credits.
Every reader looks credits up from an entry that still exists, so nothing shows the leftovers today, with one exception. Seeding creates a slugless entry in a non-routable collection under its seed ID and writes no credits for an entry without any, so re-applying a seed after a purge gave the re-created entry the old credits. Credits that earlier deletes left behind stay, and seed apply is unchanged.
Part of #1683, where the byline leftover was raised.
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change) (the fullemdashsuite)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain. (n/a: no admin UI change)AI-generated code disclosure
Screenshots / test output
Not applicable for screenshots. Against the unmodified handler, all four cases in
permanent-delete-bylines.test.tsfail on SQLite and PostgreSQL:With the change, all four pass on SQLite and PostgreSQL, and the full
emdashsuite passes on SQLite: