Appearance
Rebuild & Deployment Instructions
Follow these instructions to provision the Cloudflare resources, initialize the D1 database schema, and test/deploy the edge API.
1. Prerequisite Environment Variables
Create a local .env or set these in your terminal. Do not commit these variables to public source control.
bash
export TF_VAR_cloudflare_api_token="your-cloudflare-token"
export TF_VAR_cloudflare_account_id="your-cloudflare-account-id"2. Infrastructure Provisioning (Terraform)
Navigate to the
infra/directory:bashcd infraInitialize Terraform and fetch the Cloudflare provider:
bashterraform initGenerate a plan to review resource allocations:
bashterraform planDeploy the D1 Database and Worker placeholder:
bashterraform apply -auto-approveNote: Terraform will output the generated D1 Database ID (UUID).
3. Database Schema Initialization (Wrangler)
Navigate to the
api/directory:bashcd ../apiUpdate the
database_idvalue under[[d1_databases]]in your wrangler.toml with the database UUID outputted by Terraform.Apply the schema migration to the local D1 instance (for local dev tests):
bashnpx wrangler d1 execute event-route-optimiser-db --local --file=schema.sqlApply the schema migration to the production D1 database in Cloudflare:
bashnpx wrangler d1 execute event-route-optimiser-db --remote --file=schema.sql
4. Run & Deploy Worker
Run the local dev server:
bashnpx wrangler devDeploy the Worker script to the Cloudflare edge network:
bashnpx wrangler deploy