Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions drizzle-orm/src/cockroach-core/primary-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function primaryKey<
export class PrimaryKeyBuilder {
static readonly [entityKind]: string = 'CockroachPrimaryKeyBuilder';

declare _: {
brand: 'CockroachPrimaryKeyBuilder';
};

/** @internal */
columns: CockroachColumn[];

Expand Down
4 changes: 4 additions & 0 deletions drizzle-orm/src/mssql-core/primary-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function primaryKey<
export class PrimaryKeyBuilder {
static readonly [entityKind]: string = 'MsSqlPrimaryKeyBuilder';

declare _: {
brand: 'MsSqlPrimaryKeyBuilder';
};

/** @internal */
columns: MsSqlColumn[];

Expand Down
4 changes: 4 additions & 0 deletions drizzle-orm/src/mysql-core/primary-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export function primaryKey(...config: any) {
export class PrimaryKeyBuilder {
static readonly [entityKind]: string = 'MySqlPrimaryKeyBuilder';

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

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 👍 / 👎.


/** @internal */
columns: MySqlColumn[];

Expand Down
4 changes: 4 additions & 0 deletions drizzle-orm/src/pg-core/primary-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export function primaryKey(...config: any) {
export class PrimaryKeyBuilder {
static readonly [entityKind]: string = 'PgPrimaryKeyBuilder';

declare _: {
brand: 'PgPrimaryKeyBuilder';
};

/** @internal */
columns: PgColumn[];

Expand Down
4 changes: 4 additions & 0 deletions drizzle-orm/src/singlestore-core/primary-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export function primaryKey(...config: any) {
export class PrimaryKeyBuilder {
static readonly [entityKind]: string = 'SingleStorePrimaryKeyBuilder';

declare _: {
brand: 'SingleStorePrimaryKeyBuilder';
};

/** @internal */
columns: SingleStoreColumn[];

Expand Down
17 changes: 17 additions & 0 deletions drizzle-orm/tests/primary-keys.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, test } from 'vitest';
import { pgTable, uuid, primaryKey, getTableConfig } from '~/pg-core/index.ts';

describe('primary keys branding', () => {
test('primaryKey builder builds correctly and configures table', ({ expect }) => {
const table = pgTable('users', {
id: uuid('id').notNull(),
orgId: uuid('org_id').notNull(),
}, (t) => [
primaryKey({ columns: [t.id, t.orgId], name: 'users_pk' }),
]);

const config = getTableConfig(table);
expect(config.primaryKeys.length).toBe(1);
expect(config.primaryKeys[0]?.name).toBe('users_pk');
});
});