Skip to content

fix: normalize scheduled_at comparison on SQLite#1157

Open
jp-knj wants to merge 3 commits into
emdash-cms:mainfrom
jp-knj:fix/917-sqlite-scheduled-publishing
Open

fix: normalize scheduled_at comparison on SQLite#1157
jp-knj wants to merge 3 commits into
emdash-cms:mainfrom
jp-knj:fix/917-sqlite-scheduled-publishing

Conversation

@jp-knj
Copy link
Copy Markdown

@jp-knj jp-knj commented May 24, 2026

What does this PR do?

In SQLite, scheduled_at is stored in ISO 8601 format (2026-05-04T17:26:23Z), but datetime('now') returns 2026-05-04 17:26:23. They're compared as strings, so within the same day T is greater than a space and the row appears to be in the future. As a result, scheduled posts stayed hidden until UTC midnight.

This PR switches the right-hand side to strftime('%Y-%m-%dT%H:%M:%fZ', 'now') so both sides use the same format.

api/handlers/snapshot.ts has the same bug. I've split that fix into #1159 (currently draft) and will mark it as ready once this PR is merged.

Closes #917

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 (if applicable). 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: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.7

Copilot AI review requested due to automatic review settings May 24, 2026 06:52
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 24, 2026

🦋 Changeset detected

Latest commit: 9253748

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

This PR includes changesets to release 14 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 24, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

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

Fixes a SQLite/D1-specific scheduled publishing visibility bug caused by lexicographic comparison between ISO-8601 scheduled_at strings (...T...Z) and SQLite’s space-separated datetime('now') output, ensuring scheduled items become visible once due (matching Postgres behavior).

Changes:

  • Normalizes the SQLite scheduled_at <= now comparison in the loader’s buildStatusCondition via SQLite datetime normalization.
  • Applies the same SQLite normalization to the snapshot exporter’s published/scheduled WHERE clause.
  • Adds a dialect-parametric regression test covering past-vs-future scheduled visibility.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/loader.ts Fixes scheduled visibility logic on SQLite/D1 by normalizing scheduled_at comparisons when widening published reads to include due scheduled items.
packages/core/src/api/handlers/snapshot.ts Aligns snapshot export filtering with the corrected SQLite scheduled/published visibility predicate.
packages/core/tests/unit/loader-scheduled-publishing.test.ts Adds regression coverage across supported dialects for due vs not-due scheduled content visibility.
.changeset/red-deer-wash.md Records the patch-level change and user-facing bugfix description for release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/loader.ts
Comment thread packages/core/src/loader.ts Outdated
@jp-knj jp-knj changed the title fix(core): normalize scheduled_at comparison on SQLite fix: normalize scheduled_at comparison on SQLite May 24, 2026
@jp-knj jp-knj force-pushed the fix/917-sqlite-scheduled-publishing branch 3 times, most recently from 53c5f56 to d1ed904 Compare May 24, 2026 07:12
@jp-knj
Copy link
Copy Markdown
Author

jp-knj commented May 24, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 24, 2026
@jp-knj jp-knj force-pushed the fix/917-sqlite-scheduled-publishing branch 3 times, most recently from 89a19cd to 41ab4d6 Compare May 24, 2026 07:44
@jp-knj jp-knj force-pushed the fix/917-sqlite-scheduled-publishing branch from 41ab4d6 to b16418e Compare May 24, 2026 08:47
@jp-knj jp-knj force-pushed the fix/917-sqlite-scheduled-publishing branch from b16418e to 1ee373a Compare May 24, 2026 08:47
@jp-knj jp-knj marked this pull request as ready for review May 24, 2026 10:29
Copy link
Copy Markdown
Collaborator

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

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

Thank you!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 26, 2026

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

emdash

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

create-emdash

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

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

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 88061d5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduled posts never become visible on SQLite/D1: string comparison between ISO scheduled_at and SQLite CURRENT_TIMESTAMP always evaluates false

3 participants