Skip to content

fix: align company Drizzle schema with migration 0011 - #298

Draft
kien-ship-it wants to merge 3 commits into
mainfrom
cursor/fix-company-embedding-schema-drift-8772
Draft

fix: align company Drizzle schema with migration 0011#298
kien-ship-it wants to merge 3 commits into
mainfrom
cursor/fix-company-embedding-schema-drift-8772

Conversation

@kien-ship-it

@kien-ship-it kien-ship-it commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes schema drift where Drizzle still declared four company embedding credential columns that migration 0011 drops.
  • Removes legacy plaintext fallback reads from company-credentials so runtime matches the encrypted credentials table.
  • Relocates the backfill script under apps/web and switches it to raw SQL for older db:push databases that still have the columns.
  • Adds durable regression tests so this cannot silently regress.

Related

Closes #297

Checklist

CI status (latest head)

  • CI check
  • CI build
  • Docker build
  • Docker Build prebuilt runner
  • Vercel launch-stack / pdr-ai-v2

Reproduction (confirmed locally)

Against a clean Postgres DB:

  1. Created pdr_ai_v2_company
  2. Applied 0008_company_embedding_provider_config.sql → 4 columns present
  3. Applied 0011_drop_plaintext_embedding_credentials.sql0 rows for those columns
  4. Underlying Postgres error: column "embedding_openai_api_key" does not exist
  5. Drizzle with main schema: select() / .returning() FAIL
  6. Drizzle with this branch schema: SUCCESS

Notes for reviewers

Design choice: treat migration 0011 as the intended final state (not re-add the columns). That matches the encrypted company_embedding_credentials write path already used by signup/update.

API request fields like embeddingOpenAIApiKey in validation/settings remain — those are HTTP payload names mapped into the encrypted table, not DB columns.

Open in Web Open in Cursor 

Remove the legacy plaintext embedding credential columns from the
company Drizzle schema and drop the runtime fallback reads that still
queried them. Migration 0011 already drops those columns, so clean
migration-replayed databases failed on full company selects/returning.

Move the backfill script under apps/web and switch it to raw SQL so it
can still migrate older db:push-shaped databases that retain the
columns.

Co-authored-by: Kien Le <kien-ship-it@users.noreply.github.com>
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
launch-stack Ready Ready Preview Jul 29, 2026 8:06pm
pdr-ai-v2 Ready Ready Preview Jul 29, 2026 8:06pm

cursoragent and others added 2 commits July 29, 2026 19:57
Restore the missing Changesets config and record a patch release note
for the @launchstack/core schema/runtime alignment with migration 0011.

Co-authored-by: Kien Le <kien-ship-it@users.noreply.github.com>
Assert the company Drizzle schema and credential read path stay aligned
with migration 0011, and add an optional live DB check that select/insert
succeed after the plaintext embedding columns are dropped.

Co-authored-by: Kien Le <kien-ship-it@users.noreply.github.com>
@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Reproduction result for #297

Successfully reproduced against local Postgres:

  1. Applied 0008 → disputed columns present
  2. Applied 0011 → disputed columns gone (0 rows in information_schema)
  3. Postgres: column "embedding_openai_api_key" does not exist
  4. Main-branch Drizzle company schema: select() / .returning() fail
  5. This PR’s schema + real @launchstack/core company table: select/insert succeed

Durable coverage added in:

  • apps/web/__tests__/lib/ai/company-embedding-schema-alignment.test.ts
  • apps/web/__tests__/lib/ai/company-embedding-schema-alignment.live.test.ts

This PR uses Closes #297 so the issue is nullified on merge.

@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

CI / build wait complete — all required checks green

Check Result
CI check (typecheck + jest vs Postgres) ✅ pass
CI build (web + @launchstack/core) ✅ pass
Docker build (migration + app smoke) ✅ pass
Docker Build prebuilt runner ✅ pass
Vercel launch-stack / pdr-ai-v2 ✅ pass

#297 regression coverage in CI:

  • company-embedding-schema-alignment.test.ts — PASS
  • company-embedding-schema-alignment.live.test.ts — PASS (ran with CI DATABASE_URL after db:push)

Blocking suite: 46 suites / 461 tests passed.

Legacy baseline job still fails (pre-existing, continue-on-error: true) — unrelated to this change.

No further code changes needed for e2e/build compatibility.

@Deodat-Lawson

Copy link
Copy Markdown
Owner

yo @kien-ship-it lmk when its ready for review

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.

[bug]: Drizzle company schema references embedding columns dropped by migration 0011

3 participants