BuildRight Contractors Portal
Deployment
Build, deploy, and database migration procedures
Last updated: 2026-07-12
Windows terminal required: Both npm run build and wrangler deploy must be run from the user's Windows terminal. The sandbox/AI environment cannot run esbuild Windows binaries or authenticate with Cloudflare (gets 403).

Overview

The portal has two deployable pieces:

  1. Cloudflare Pages — serves the React frontend. Auto-deploys when main is pushed to GitHub.
  2. Cloudflare Worker — serves the API (buildright-api.sonandigital.com). Deployed manually with Wrangler.

Frontend Deploy (Cloudflare Pages)

  1. Build the frontend:
    cd E:\Claude_Projects\sonan-trackers\contractor-portal
    npm run build
  2. Push the commit to GitHub main (from Windows terminal):
    git push origin <commit_sha>:refs/heads/main
  3. Cloudflare Pages automatically picks up the push and deploys the dist/ folder.
  4. Live at: buildright.sonandigital.com

Worker Deploy (API)

  1. Ensure wrangler.toml is correct (D1 binding, worker name buildright)
  2. Deploy the worker from Windows terminal:
    cd E:\Claude_Projects\sonan-trackers\contractor-portal
    npx wrangler deploy
  3. Live at: buildright-api.sonandigital.com

GitHub Push (FUSE-Safe Pattern)

Because the repo lives on a FUSE mount, .git/config is always corrupted after an AI session. Before pushing, run all of these from the Windows terminal:

del .git\config.lock
echo [core] > .git\config
echo     repositoryformatversion = 0 >> .git\config
echo     filemode = false >> .git\config
echo     bare = false >> .git\config
git remote add origin https://github.com/sonantechai/contractor-portal.git
git push origin <commit_sha>:refs/heads/main

Current latest pushed SHA: ec6702c81726efb2c967be56c8267b281dd4ba13

Database Migrations

Migrations live in migrations/ at the repo root.

MigrationContentsStatus
0001_init.sqlAll tables: settings, clients, service_requests, jobs, estimates, invoices, appointments, employeesApplied to remote D1
0006_recurring_appointments.sqlAdds recurring, recurrence, recurring_end_date columns to appointmentsApplied to remote D1
0007_recurring_days.sqlAdds recurring_days (JSON array of day indices) column to appointmentsApplied to remote D1
Employees table: The employees table was created as part of the initial 0001_init.sql migration — it was always part of the schema. No separate migration is needed for the employee / Team feature.

Migrations 0001 through any subsequent ones are already applied to the remote D1 database (contractor_db, UUID: 5f5efd19-3979-4c1b-a75c-ebd9e2256736).

Running a new migration

If a new migration is needed in future:

npx wrangler d1 execute contractor_db --remote --file=migrations/0002_new_migration.sql

Environment / Secrets

No environment variables are required for the Worker beyond what is in wrangler.toml (D1 binding). Auth secrets (PBKDF2 salt, JWT secret) are hardcoded defaults in the worker — they can be moved to Wrangler secrets if needed:

npx wrangler secret put JWT_SECRET

Local Development

# Frontend dev server
npm run dev

# Worker local (with D1 local emulation)
npx wrangler dev worker/index.ts --local --persist

Local D1 is separate from remote D1. Changes to local are not reflected in production.