Skip to content

fix: brand PrimaryKeyBuilder to close empty structural type hole - #6189

Open
webdevsamran wants to merge 1 commit into
drizzle-team:rc5from
webdevsamran:fix/issue-6140-extra-config-primary-key-brand
Open

fix: brand PrimaryKeyBuilder to close empty structural type hole#6189
webdevsamran wants to merge 1 commit into
drizzle-team:rc5from
webdevsamran:fix/issue-6140-extra-config-primary-key-brand

Conversation

@webdevsamran

Copy link
Copy Markdown

Fixes #6140

Summary

In published type definitions, PrimaryKeyBuilder had its instance properties stripped due to /** @internal */ comments, leaving it structurally empty ({}).

Consequently, arbitrary plain objects or object-wrapped builders (such as [{ myIndex: uniqueIndex(...) }] when migrating from legacy object syntax) satisfied TableExtraConfigValue without TypeScript reporting any diagnostic, which caused indexes to be silently ignored at runtime.

Changes

  • Added declare _: { brand: 'PrimaryKeyBuilder' } to PrimaryKeyBuilder in pg-core, mysql-core, singlestore-core, cockroach-core, and mssql-core (matching sqlite-core).
  • Added unit test in drizzle-orm/tests/primary-keys.test.ts.

In the published declarations, PrimaryKeyBuilder had its instance
properties stripped by @internal markers, causing it to be structurally
empty ({}). As a result, arbitrary plain objects or wrapped index objects
(e.g. { myIndex: uniqueIndex(...) }) satisfied PgTableExtraConfigValue
without compiler error, leading to silently dropped indexes.

Fix: add nominal declare _: { brand: '<Dialect>PrimaryKeyBuilder' }`nbranding to PrimaryKeyBuilder across pg, mysql, singlestore, cockroach,
and mssql dialects (matching sqlite).

Fixes drizzle-team#6140

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c394ab52e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +28 to +30
declare _: {
brand: 'MySqlPrimaryKeyBuilder';
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Brand the remaining empty MySQL union member

For consumers of the published MySQL declarations, this brand still does not reject legacy object-wrapped indexes: MySqlTableExtraConfigValue also includes UniqueConstraintBuilder, whose columns, name, and build members are all stripped as @internal, leaving only a constructor, which does not participate in structural instance compatibility. Consequently that union still accepts arbitrary objects such as { myIndex: uniqueIndex(...) }, so MySQL users continue to receive no diagnostic and the index remains silently ignored; UniqueConstraintBuilder must also retain a structural discriminator.

Useful? React with 👍 / 👎.

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