Skip to content

fix: DB interface uses Type for regular tables, Encoded for join tables#31

Merged
samuelho-dev merged 1 commit into
mainfrom
fix/db-interface-type-for-regular-tables
May 8, 2026
Merged

fix: DB interface uses Type for regular tables, Encoded for join tables#31
samuelho-dev merged 1 commit into
mainfrom
fix/db-interface-type-for-regular-tables

Conversation

@samuelho-dev

Copy link
Copy Markdown
Owner

Summary

5.7.0 flipped the DB interface to Schema.Schema.Encoded for all tables to fix the join-table column-name bug (_product_tags.product_id was decoded-name; SQL needs A). That was right for join tables but accidentally stripped branded IDs for regular tables — Schema.Schema.Encoded<typeof X> strips Schema.brand(...) because brands live on the Type side.

Concrete consequence: every Kysely consumer queried result.seller_id: string instead of result.seller_id: string & Brand<\"SellerId\">. Branded ID type safety silently disabled across the entire monorepo.

Fix

Pick the side per table category:

  • Regular tables: Schema.Schema.Type<typeof X> — preserves branded IDs (string & Brand<\"SellerId\">) and ColumnType<S, I, U> phantoms. Type === Encoded for column names anyway because regular tables don't use Schema.fromKey.
  • Join tables: Schema.Schema.Encoded<typeof X> — preserves real DB column names A/B. Type would expose decoded names that Kysely passes to SQL verbatim → "column does not exist".

Tests

db-interface-sql-contract.test.ts updated to assert both: regular tables use Type, join tables use Encoded. The Kysely SQL-compile test (catches the original join-table bug at the SQL level) stays.

Migration

Regular-table consumers regain Brand<...> IDs immediately. Join-table consumers (_product_tags.A/B queries) unchanged from 5.7.0.

🤖 Generated with Claude Code

…hema.Encoded

5.7.0 flipped the DB interface to Schema.Schema.Encoded for all tables
to fix the join-table column-name bug. That was correct for join tables
(they use Schema.fromKey to remap A/B → semantic names; Encoded preserves
real DB columns), but accidentally stripped branded IDs across all
regular tables. Schema.Schema.Encoded strips Schema.brand(...) because
brands live on the Type side.

Fix: pick the side that matches the intended consumer view per table
category.

- Regular tables: Schema.Schema.Type — preserves branded IDs and
  ColumnType phantoms. Type === Encoded for column names anyway since
  regular tables don't use Schema.fromKey.
- Join tables: Schema.Schema.Encoded — preserves real DB column names
  A/B. Type would expose Schema.fromKey-decoded names that Kysely passes
  to SQL verbatim → "column does not exist".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 8, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@samuelho-dev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 37 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2e348199-300c-432a-9fe4-473de69bc724

📥 Commits

Reviewing files that changed from the base of the PR and between 355d20a and d8211f5.

📒 Files selected for processing (7)
  • .changeset/db-interface-type-for-regular.md
  • src/__tests__/code-generation.test.ts
  • src/__tests__/db-interface-sql-contract.test.ts
  • src/__tests__/kysely-integration.test.ts
  • src/__tests__/kysely-native-integration.test.ts
  • src/__tests__/multi-domain.test.ts
  • src/kysely/type.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/db-interface-type-for-regular-tables

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@samuelho-dev samuelho-dev merged commit 5f07c8f into main May 8, 2026
6 checks passed
@samuelho-dev samuelho-dev deleted the fix/db-interface-type-for-regular-tables branch May 8, 2026 06:04
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.

1 participant