Replies: 1 comment
-
|
I like option 1. If EmDash is creating the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I'm embedding EmDash inside a larger system that wants to provide its own initial schema (different collections and field names than
defaultSeed) via a customapplySeed()call right after the EmDash worker comes online. This works most of the time, but I've hit a race condition in the auto-seed path that I'd love to get maintainer guidance on before opening a PR.What's happening
The
astroEmdashmiddleware auto-appliesdefaultSeedon the very first DB hit when:_emdash_collectionsis empty, ANDemdash:setup_completeis unset in_emdash_settingsIf anything triggers a DB-touching request to the EmDash worker between deploy and my own seed-apply call, the auto-seed wins:
_emdash_collectionsOnce that happens,
_emdash_collectionshas the defaultpostscollection (withcontentfield), and a subsequentapplySeed({ schema, onConflict: 'skip' })silently no-ops on the already-existing collection. The resulting DB ends up with the wrong schema (ec_posts.contentexists; myec_posts.bodydoesn't), and the first content insert fails withD1_ERROR: table ec_posts has no column named body.Switching to
onConflict: 'update'works as a salvage path because it lets my seed patch the auto-applied collection in place. But it's a workaround with rough edges:defaultSeedwon't grow new fields/indexes that conflict.Minimal repro
After the second POST,
_emdash_collectionsstill reflectsdefaultSeed, notcustomSchema.I'd love guidance on which of these you'd accept
A few options I've considered, in order of intrusiveness:
1. Opt-out flag on
astroEmdash()When
false, middleware skips the auto-seed branch and waits for an explicitapplySeedcall. Simple, additive, fully backwards-compatible. The embedder is responsible for ensuringapplySeedruns before the first user-facing request — which is already a constraint they've taken on by setting the flag.2. Atomic-bootstrap helper
Expose a function the embedder can call before the first request that writes BOTH
_emdash_collectionsANDemdash:setup_completein a single transaction:Beta Was this translation helpful? Give feedback.
All reactions