Skip to content

fix: preserve revisionless content on publish - #2460

Merged
ascorbic merged 2 commits into
mainfrom
fix/revisionless-publish-data-loss
Aug 13, 2026
Merged

ascorbic merged 2 commits into
mainfrom
fix/revisionless-publish-data-loss

Conversation

@ascorbic

Copy link
Copy Markdown
Member

What does this PR do?

Prevents publishing a collection without revisions support from replacing current content-table values with stale data from live_revision_id. Revisionless publishing now updates lifecycle metadata only, while revision-enabled collections continue promoting the staged draft revision normally.

Closes #2095

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (not applicable; no admin UI changes). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: not applicable; this is a bug fix.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI Codex (GPT-5)

Screenshots / test output

Not applicable; this is a non-visual data-layer fix.

Validation:

  • pnpm lint:json | jq '.diagnostics | length' — 0
  • pnpm lint:quick
  • pnpm lint
  • pnpm typecheck
  • pnpm --filter emdash exec vitest run tests/integration/mcp/drafts.test.ts tests/unit/database/repositories/content.test.ts tests/unit/scheduled-publish.test.ts tests/integration/seed-live-revisions.test.ts — 98 tests passed

Copilot AI lite review requested due to automatic review settings August 13, 2026 15:17
@changeset-bot

changeset-bot Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a9f0056

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/plugin-mcp-smoke Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground a9f0056 Aug 13 2026, 04:09 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache a9f0056 Aug 13 2026, 04:09 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do a9f0056 Aug 13 2026, 04:11 PM

@github-actions github-actions Bot added area/core size/M review/needs-review No maintainer or bot review yet labels Aug 13, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR fixes the right bug in the right place. Publishing for collections that don't support revisions was syncing data from a stale live_revision_id into the content columns, overwriting edits made via direct column updates. The change makes ContentRepository.publish() accept a promoteRevision flag and, when false, perform a lifecycle-only UPDATE (status → published, clear scheduled_at, set published_at/updated_at, bump version) without touching field columns or live/draft revision pointers. The handler determines the collection's revision support from _emdash_collections.supports and passes the flag accordingly, so revision-enabled collections continue to promote drafts normally.

I checked the full diff and supporting code: the new branch is SQL-safe (uses sql.ref for identifiers and parameterized values), preserves optimistic-concurrency and scheduled-due fences, re-stamps the taxonomy pivot and invalidates the collection cache the same way the promote path does, and reuses the existing reconciliation helpers. The regression test in drafts.test.ts reproduces the stale-revision scenario and asserts the current column data survives publish. The changeset is user-facing and concise. There are no new logged-out queries, no admin UI strings requiring localization, and no new indexes needed.

The code is clean; I found no blocking issues.

@pkg-pr-new

pkg-pr-new Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@2460

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@2460

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@2460

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@2460

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@2460

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@2460

emdash

npm i https://pkg.pr.new/emdash@2460

create-emdash

npm i https://pkg.pr.new/create-emdash@2460

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@2460

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2460

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2460

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2460

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2460

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2460

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2460

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@2460

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@2460

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@2460

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@2460

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@2460

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@2460

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2460

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@2460

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@2460

commit: a9f0056

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-review No maintainer or bot review yet labels Aug 13, 2026
@ascorbic
ascorbic enabled auto-merge (squash) August 13, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a data-loss bug where publishing entries in collections that don’t support revisions could overwrite current column data with stale data from live_revision_id. The change introduces a “lifecycle-only” publish path for revisionless collections, while keeping the existing revision-promotion behavior for revision-enabled collections.

Changes:

  • Add a promoteRevision option to ContentRepository.publish() to support lifecycle-only publishing (no column sync).
  • Update handleContentPublish() to decide whether to promote a revision based on collection supports.
  • Add an integration regression test reproducing “stale live revision overwrites fresh columns” for a non-revision collection, plus a changeset entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/core/tests/integration/mcp/drafts.test.ts Adds regression coverage for publishing on non-revision collections when live_revision_id is stale.
packages/core/src/database/repositories/content.ts Implements lifecycle-only publish path via promoteRevision flag and reconciliation helper.
packages/core/src/api/handlers/content.ts Detects whether a collection supports revisions and passes that into repo.publish().
.changeset/calm-pandas-publish.md Patch changeset describing the bug fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot added size/L review/needs-rereview New commits since the last review and removed size/M review/approved Approved; no new commits since labels Aug 13, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Aug 13, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a re-review: my previous approval stands and there are no new blocking issues.

Approach judgment: The fix is the right change in the right place. Publishing should not overwrite current content-table values with stale revision data for collections that don't support revisions. Adding a promoteRevision flag to ContentRepository.publish() and driving it from the handler's check of _emdash_collections.supports keeps the repository generic while fixing the API/MCP/scheduled-publish entry points in one place. The default promoteRevision = true preserves backward compatibility for all existing callers.

What I re-checked:

  • SQL safety: The new lifecycle-only branch uses sql.ref() for the dynamic table name and nullableColumnMatch() (which validates identifiers) for nullable lifecycle columns; all values are parameterized. No string interpolation into SQL.
  • Concurrency/correctness: The lifecycle-only UPDATE keeps the same optimistic-concurrency fence (version, status, live_revision_id, draft_revision_id, scheduled_at) as the promote path, bumps version, preserves published_at when no override is supplied, clears stale draft_revision_id, and only creates a provisional live revision when none exists. It also reuses the existing reconciliation helper and provisional-revision cleanup logic.
  • Cross-cutting paths: scheduled-publish.ts and EmDashRuntime.handleContentPublish both route through handleContentPublish, so they inherit the lifecycle-only behavior automatically. seed/apply.ts still calls publish() with the default promoteRevision = true; it remains safe because seed data is self-consistent (the draft revision created before publish carries the same data as the updated columns).
  • Tests: The added regression tests in drafts.test.ts cover first publish, an unexpected stale draft pointer, and a stale live_revision_id — all observable outcomes, not implementation-detail tautologies.
  • AGENTS.md conventions: Changeset is present and user-facing; no new logged-out queries; no admin UI strings requiring Lingui/RTL work; no new indexes required.

No findings to report; the PR is clean.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 13, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Aug 13, 2026
@ascorbic
ascorbic merged commit d236776 into main Aug 13, 2026
54 checks passed
@ascorbic
ascorbic deleted the fix/revisionless-publish-data-loss branch August 13, 2026 16:43
@emdashbot emdashbot Bot mentioned this pull request Aug 13, 2026
khoinguyenpham04 pushed a commit that referenced this pull request Aug 14, 2026
…ublish (#2466)

* fix(core): remove stale restampEntryPivot call that crashes content publish

The merge of #2460 and #2461 left main with a publish path that calls
restampEntryPivot, a method #2461 deleted together with the pivot
denormalization it maintained. Every content publish now throws
"this.restampEntryPivot is not a function".

No replacement call is needed: since migration 068 the pivot columns the
call re-stamped are legacy, and reads join the authoritative ec_* row.

* chore: add changeset for the publish crash fix

The fix changes the published emdash package, and release notes are
built from changeset files, so the crash fix needs an entry even though
the crash itself never shipped in a release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core review/approved Approved; no new commits since size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

publish silently reverts content on collections without revisions support

2 participants