diff --git a/drizzle-orm/src/cockroach-core/primary-keys.ts b/drizzle-orm/src/cockroach-core/primary-keys.ts index e89352fbd2..b89c951e22 100644 --- a/drizzle-orm/src/cockroach-core/primary-keys.ts +++ b/drizzle-orm/src/cockroach-core/primary-keys.ts @@ -13,6 +13,10 @@ export function primaryKey< export class PrimaryKeyBuilder { static readonly [entityKind]: string = 'CockroachPrimaryKeyBuilder'; + declare _: { + brand: 'CockroachPrimaryKeyBuilder'; + }; + /** @internal */ columns: CockroachColumn[]; diff --git a/drizzle-orm/src/mssql-core/primary-keys.ts b/drizzle-orm/src/mssql-core/primary-keys.ts index 3f320874f2..3ce6ac753b 100644 --- a/drizzle-orm/src/mssql-core/primary-keys.ts +++ b/drizzle-orm/src/mssql-core/primary-keys.ts @@ -13,6 +13,10 @@ export function primaryKey< export class PrimaryKeyBuilder { static readonly [entityKind]: string = 'MsSqlPrimaryKeyBuilder'; + declare _: { + brand: 'MsSqlPrimaryKeyBuilder'; + }; + /** @internal */ columns: MsSqlColumn[]; diff --git a/drizzle-orm/src/mysql-core/primary-keys.ts b/drizzle-orm/src/mysql-core/primary-keys.ts index a3e60993cd..660295bcc9 100644 --- a/drizzle-orm/src/mysql-core/primary-keys.ts +++ b/drizzle-orm/src/mysql-core/primary-keys.ts @@ -25,6 +25,10 @@ export function primaryKey(...config: any) { export class PrimaryKeyBuilder { static readonly [entityKind]: string = 'MySqlPrimaryKeyBuilder'; + declare _: { + brand: 'MySqlPrimaryKeyBuilder'; + }; + /** @internal */ columns: MySqlColumn[]; diff --git a/drizzle-orm/src/pg-core/primary-keys.ts b/drizzle-orm/src/pg-core/primary-keys.ts index 452138df95..0aafa6f0d4 100644 --- a/drizzle-orm/src/pg-core/primary-keys.ts +++ b/drizzle-orm/src/pg-core/primary-keys.ts @@ -25,6 +25,10 @@ export function primaryKey(...config: any) { export class PrimaryKeyBuilder { static readonly [entityKind]: string = 'PgPrimaryKeyBuilder'; + declare _: { + brand: 'PgPrimaryKeyBuilder'; + }; + /** @internal */ columns: PgColumn[]; diff --git a/drizzle-orm/src/singlestore-core/primary-keys.ts b/drizzle-orm/src/singlestore-core/primary-keys.ts index 36bedd1acf..0efb670e0c 100644 --- a/drizzle-orm/src/singlestore-core/primary-keys.ts +++ b/drizzle-orm/src/singlestore-core/primary-keys.ts @@ -25,6 +25,10 @@ export function primaryKey(...config: any) { export class PrimaryKeyBuilder { static readonly [entityKind]: string = 'SingleStorePrimaryKeyBuilder'; + declare _: { + brand: 'SingleStorePrimaryKeyBuilder'; + }; + /** @internal */ columns: SingleStoreColumn[]; diff --git a/drizzle-orm/tests/primary-keys.test.ts b/drizzle-orm/tests/primary-keys.test.ts new file mode 100644 index 0000000000..1e6ff3caf4 --- /dev/null +++ b/drizzle-orm/tests/primary-keys.test.ts @@ -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'); + }); +});