Deployment and updates
Deploying
Section titled “Deploying”npm run deployThis 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.
Deploying on push
Section titled “Deploying on push”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.
Updating to a new version
Section titled “Updating to a new version”With the command line:
git pull # or pull from the upstream repository into your copynpm installnpm run deployIf 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:
git remote add upstream https://github.com/kihitara/dragonslaircms.git # oncegit pull upstream maingit pushBefore 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.
A custom domain
Section titled “A custom domain”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.
Logs and rolling back
Section titled “Logs and rolling back”npx wrangler tail # live logs from the deployed Workernpx wrangler rollback # go back to the previous deploymentUnhandled 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.
