Skip to content

fix: use D1 migrations for worker database#25

Merged
rupurt merged 1 commit intomainfrom
fix-worker-deploy
Dec 25, 2025
Merged

fix: use D1 migrations for worker database#25
rupurt merged 1 commit intomainfrom
fix-worker-deploy

Conversation

@rupurt
Copy link
Copy Markdown
Contributor

@rupurt rupurt commented Dec 25, 2025

Summary

  • Switch from raw schema.sql execution to D1 migrations
  • Create 0001_initial.sql with base schema (original tables)
  • Keep 0002_interview_fields.sql for adding interview columns
  • Update deploy workflow and justfile to use d1 migrations apply

Problem

The worker deploy was failing with no such column: lead_tier because:

  1. Production DB was created before interview fields were added
  2. CREATE TABLE IF NOT EXISTS doesn't update existing tables
  3. Indexes tried to reference columns that don't exist

Solution

D1 migrations track which migrations have been applied:

  • 0001 creates base tables (skips if they exist)
  • 0002 adds new columns via ALTER TABLE

Test Plan

  • All unit tests pass
  • Deploy worker to staging
  • Deploy worker to production

- Create 0001_initial.sql with base schema (tables without interview fields)
- Keep 0002_interview_fields.sql for adding new columns
- Update deploy-worker.yml to use 'd1 migrations apply'
- Update justfile worker-migrate to use migrations

This fixes the 'no such column: lead_tier' error when deploying to
a production database that was created before interview fields were added.
Copilot AI review requested due to automatic review settings December 25, 2025 00:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the worker database setup from direct SQL file execution to D1's migration system to fix a deployment issue where new columns were missing in production. The migration system tracks applied changes, ensuring existing tables are properly updated with new columns rather than skipped by CREATE TABLE IF NOT EXISTS statements.

Key Changes:

  • Creates structured D1 migrations (0001_initial.sql for base schema, 0002_interview_fields.sql for new columns)
  • Updates deployment commands in GitHub Actions and justfile to use d1 migrations apply instead of direct SQL execution

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
workers/chat-api/migrations/0001_initial.sql Initial migration containing base schema for sessions, messages, and leads tables
justfile Updated worker-migrate command to use D1 migrations API across all environments
.github/workflows/deploy-worker.yml Updated deployment workflow to apply migrations instead of executing raw SQL

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rupurt rupurt enabled auto-merge December 25, 2025 00:36
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
vibes-website 2e15bb4 Commit Preview URL

Branch Preview URL
Dec 25 2025, 12:36 AM

@rupurt rupurt merged commit 7689a4c into main Dec 25, 2025
3 checks passed
@rupurt rupurt deleted the fix-worker-deploy branch December 25, 2025 00:37
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.

2 participants