Repository navigation
Description
Description
Description
Publishing any content (posts, pages, custom collections) fails with 500 on Cloudflare D1. Saving drafts works fine. Affects every collection that has search enabled.
Error
Content publish error: Error: D1_ERROR: database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB)
Root cause identified
The bug is in FTSManager.verifyAndRepairIndex() in packages/core/src/search/fts-manager.ts.
This line runs on every Worker startup:
INSERT INTO "ftsTable"("{ftsTable}"("
ftsTable"("{ftsTable}") VALUES('integrity-check')
This FTS5 integrity-check command corrupts D1's FTS5 shadow tables. After corruption, the FTS triggers fire on every content update and cause publish to fail.
Workaround
Drop all FTS tables and triggers, then set search_config to disabled:
UPDATE _emdash_collections SET search_config = '{"enabled":false}' WHERE search_config IS NOT NULL;Then drop all _emdash_fts_* tables and triggers manually via D1 console.
Suggested fix
Skip the integrity-check INSERT on D1, or catch the corruption and drop/rebuild rather than leaving tables in a corrupted state.
Environment
- [email protected]
- @emdash-cms/[email protected]
- Cloudflare D1 + paid Workers plan
Steps to reproduce
Steps to reproduce
- Deploy EmDash to Cloudflare Workers with D1 database
- Run setup wizard and create admin account
- Create any collection with at least one searchable field
- Create a content item in that collection and save as draft — works fine
- Click Publish — fails with 500
- Check Cloudflare Observability logs — shows SQLITE_CORRUPT_VTAB
- Repeat for any collection (posts, pages, videos, custom) — all fail
Additional notes
- The corruption happens on every Worker cold start because verifyAndRepairIndex() runs at startup
- The integrity-check INSERT leaves the FTS5 shadow tables in a corrupted state
- The corrupted triggers then fire on every content UPDATE, causing publish to fail
- Dropping the FTS tables and triggers manually restores publish functionality
- The issue recurs whenever EmDash recreates FTS tables for a new collection
- This affects ALL content publishing on D1 — making the CMS unusable for production on Cloudflare without the manual workaround
Environment
Environment
- emdash: 0.1.0
- @emdash-cms/cloudflare: 0.1.0
- @emdash-cms/plugin-audit-log: 0.1.0
- @emdash-cms/plugin-forms: 0.1.0
- Cloudflare Workers (paid plan)
- Cloudflare D1 database
- Cloudflare R2 storage
- Cloudflare Worker Loader (Dynamic Workers)
- Wrangler: 4.80.0
- Node.js: 22.16.0
- Bun: 1.2.15
Logs / error output
## Logs / error output
From Cloudflare Observability:
Content publish error: Error: D1_ERROR: database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB)
Worker startup logs (repeating on every cold start):
FTS index for "pages" has 2 rows but content table has 1. Rebuilding.
Repaired 1 corrupted FTS index(es) at startup
Publish API call:
POST /_emdash/api/content/posts/{id}/publish → 500
POST /_emdash/api/content/pages/{id}/publish → 500
POST /_emdash/api/content/videos/{id}/publish → 500
Browser console:
Failed to load resource: the server responded with a status of 500
/_emdash/api/content/posts/{id}/publish
Activity
fix(core): remove FTS5 integrity-check to prevent D1 shadow table cor…
mvanhorn commentedon Apr 6, 2026
Implemented in #313 - removes the FTS5 integrity-check INSERT that corrupts D1 shadow tables. Row-count mismatch detection is kept as a safe alternative.
fix(core): remove FTS5 integrity-check to prevent D1 shadow table cor…
fix(core): remove FTS5 integrity-check to prevent D1 shadow table cor…
fix(d1): disable FTS5 triggers to avoid SQLITE_CORRUPT_VTAB on save
fix(d1): disable FTS5 triggers to avoid SQLITE_CORRUPT_VTAB on save
DavidPivert commentedon May 18, 2026
Heads-up for anyone debugging a similar symptom on emdash ≥ 0.12 (where the PR #313 fix is shipped):
The startup
verifyAndRepairIndex()is fixed, but theINSERT INTO ftsTable(ftsTable) VALUES('integrity-check')command itself is still dangerous on D1 if you run it manually (e.g. while diagnosing FTS issues).I hit this on emdash 0.12.0 on Cloudflare D1:
defineConfig({ i18n: {...} })), publishing an existing FR variant of a translated page started failing withSQLITE_CORRUPT_VTABec_*tables get recreated by019_i18n, but the FTS shadow tables aren't rebuilt at the same time)INSERT INTO _emdash_fts_pages(_emdash_fts_pages) VALUES('integrity-check')returnedsuccess: truebut silently corrupted the shadow tables — every subsequent UPDATE onec_pagesthen failed withSQLITE_CORRUPT_VTABTwo suggestions for the docs / repo:
migrations/019_i18n.tsalso rebuild the FTS shadow tables when it rebuilds the content tables? Currently they end up referencing rowids from a dropped table.INSERT INTO fts(fts) VALUES('integrity-check')manually on D1 would have saved me a couple of hours.Happy to file a fresh issue for either if it would be more useful.
ascorbic commentedon May 19, 2026
#768 will be going out in a release today which should fix this properly