Skip to content

fix(ci): drop D1 migration step + add Paraglide compile to deploy job#51

Open
thunpisit wants to merge 1 commit into
codustry:mainfrom
thunpisit:fix/ci-d1-migration-token-scope
Open

fix(ci): drop D1 migration step + add Paraglide compile to deploy job#51
thunpisit wants to merge 1 commit into
codustry:mainfrom
thunpisit:fix/ci-d1-migration-token-scope

Conversation

@thunpisit

Copy link
Copy Markdown
Contributor

Summary

Two CI bugs that bite every fresh fork of khaopad. Both surfaced when bootstrapping codustry/drvakuum-website from this template — would have hit codustry/bactrack-website too if it weren't for the workaround in its deploy.yml.

1. D1 migration step fails with 7403

Symptom on a fresh fork after wiring CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID correctly:

```
✘ ERROR A request to the Cloudflare API
/accounts//d1/database//query failed.

The given account is not valid or is not authorized to access
this service [code: 7403]
```

Even though the deploy step against the same account works fine.

Root cause: the conventional org-wide CLOUDFLARE_API_TOKEN is created from the "Edit Cloudflare Workers" template, which only grants Workers Scripts — Edit. D1's REST API needs the separate D1 — Edit permission. The 7403 error message doesn't mention permissions, which makes this hard to diagnose.

Fix: drop the D1 step entirely, document the out-of-band command inline. Same pattern codustry/bactrack-website settled on (their deploy.yml has the same comment block I'm proposing here).

If a fork wants migrations in CI, they can create a repo-level CLOUDFLARE_API_TOKEN with D1 — Edit added (it overrides the org-wide one for that repo only) and re-add a migration step.

2. Deploy job missing Paraglide compile

The deploy job runs pnpm build without first compiling Paraglide messages. src/lib/paraglide is gitignored, and each GitHub Actions job gets a fresh runner — so the gate job's compile output doesn't carry over. On any non-trivial fork the build fails on missing imports from \$lib/paraglide/messages.

Fix: add the same compile step the gate job already has.

Test plan

  • Verified the same workflow shape (D1 step removed, paraglide compile added to deploy job) on codustry/drvakuum-website — first deploy went green: gate ✅ resolve-env ✅ deploy ✅ smoke-test ✅
  • Worker live at https://drvakuum-website.codustry.workers.dev
  • Migrations applied locally with the documented command

🤖 Generated with Claude Code

Two issues hit when forking khaopad to a new project (caught by
codustry/drvakuum-website during its first deploy):

1. D1 migration step fails with HTTP 7403 "account is not valid or
   not authorized" even when CLOUDFLARE_ACCOUNT_ID is set correctly.

   Root cause: the conventional `CLOUDFLARE_API_TOKEN` created from
   the "Edit Cloudflare Workers" template only grants `Workers
   Scripts — Edit`. D1's REST API needs the separate `D1 — Edit`
   permission. The deploy step itself works because it only needs
   Workers Scripts.

   Fix: drop the D1 step entirely, document the out-of-band command
   inline. Same pattern codustry/bactrack-website settled on.

2. Deploy job's `pnpm build` would fail because `src/lib/paraglide`
   is gitignored and the deploy job never compiled it. The gate job
   compiles it but each runner is fresh, so the artifact doesn't
   carry over. Adding the same compile step to the deploy job.

Both bugs are silent on a freshly-forked repo because the gate job
gates the deploy — by the time someone hits codustry#1, they've already had
to set up CLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID and probably
spent time wondering whether the token scope was wrong (it's not).
The 7403 error message doesn't mention permissions, which makes
this even harder to diagnose.

Migrations are still trivial to apply manually:

  CLOUDFLARE_ACCOUNT_ID=<id> pnpm exec wrangler d1 migrations apply \
    khaopad-db --remote --env staging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant