Skip to content

Deployment and updates

Terminal window
npm run deploy

This runs npm run db:schema:remote && wrangler deploy: it applies schema.sql to the deployed database, then deploys the Worker. Because the schema is idempotent, applying it on every deploy is safe, and a new table never needs a separate step. (New columns on existing tables do; see Upgrading an existing database.)

Wrangler needs to be authorised: npx wrangler login on your own machine, or the CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID credentials in CI. See CLI credentials for CI.

The first wrangler deploy of a wrangler.jsonc without a database_id creates the D1 database and R2 bucket and writes the database ID back into the file. Keep that change (commit it, in your own copy of the repository), so later deploys use the same database.

Pages, articles, settings and media all live in D1 and R2, so deploying new code never touches your content.

If you installed with the Deploy to Cloudflare button, your copy of the repository is already connected to the Worker: every push to its main branch builds and deploys it.

If you connect a repository yourself (in the Cloudflare dashboard, under the Worker’s Settings → Build), set the deploy command to npm run deploy, not plain npx wrangler deploy, so the schema is applied on each deploy.

With the command line:

Terminal window
git pull # or pull from the upstream repository into your copy
npm install
npm run deploy

If you installed with the button, your repository is a copy of the original. To take an update, pull the original’s changes into it and push, and the push deploys:

Terminal window
git remote add upstream https://github.com/kihitara/dragonslaircms.git # once
git pull upstream main
git push

Before deploying an update, check schema.sql for new Migration (pre-existing databases) comments (git diff shows them) and run them against your database. A new column that hasn’t been added can break the pages that use it.

To serve the site from your own domain instead of *.workers.dev, add the domain to the Worker in the Cloudflare dashboard (Settings → Domains & Routes). Then, as an admin, change Site URL (canonical) in the admin’s Settings to the new https:// address, so the RSS feed, the sitemap and emails use it.

Terminal window
npx wrangler tail # live logs from the deployed Worker
npx wrangler rollback # go back to the previous deployment

Unhandled errors, email failures ([email]) and the scheduled job ([schedule]) all log there. A rollback changes the code only; it doesn’t undo schema changes or content.