Skip to content

Conversation

@rabble
Copy link
Member

@rabble rabble commented Jan 25, 2026

Summary

  • Adds automatic database migration step to Cloud Build pipeline that runs before deployment
  • Prevents schema drift issues like the missing vine_id column that broke preload-user idempotency
  • Makes migrations 0003 and 0005 idempotent with IF NOT EXISTS clauses

How It Works

  1. Cloud Build step installs PostgreSQL client and Cloud SQL Proxy
  2. Connects to production database via Cloud SQL Proxy with IAM auth
  3. Runs migrations 0002+ (skips 0001 initial schema which is not idempotent)
  4. All skipped migrations use IF NOT EXISTS so they're safe to re-run

IMPORTANT: First Deploy

Before merging this PR, you need to manually run migrations 0004 and 0005 in Cloud SQL Studio:

-- Migration 0004: Preloaded accounts
ALTER TABLE users ADD COLUMN IF NOT EXISTS display_name TEXT;
ALTER TABLE users ADD COLUMN IF NOT EXISTS vine_id TEXT;
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_vine_id_tenant ON users(tenant_id, vine_id) WHERE vine_id IS NOT NULL;
CREATE TABLE IF NOT EXISTS account_claim_tokens (...);

-- Migration 0005: is_headless column
ALTER TABLE oauth_codes ADD COLUMN IF NOT EXISTS is_headless BOOLEAN NOT NULL DEFAULT FALSE;

After that, future deployments will run migrations automatically.

Test plan

  • Run migrations 0004 and 0005 manually in Cloud SQL Studio first
  • Merge PR and trigger deployment
  • Verify Cloud Build logs show migration step completing
  • Test preload-user endpoint returns same pubkey for same vine_id

🤖 Generated with Claude Code

- Add migration step in cloudbuild.yaml that runs before deployment
- Uses Cloud SQL Proxy to connect to production database
- Skips 0001 (initial schema, not idempotent) - assumes DB initialized
- Migrations 0002+ are idempotent and safe to re-run
- Make 0003 and 0005 idempotent with IF NOT EXISTS clauses
- Update CLAUDE.md to reflect automatic migration behavior

This ensures schema changes are applied automatically during deployment,
preventing issues like missing columns when new code expects them.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

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.

3 participants