drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Left Join PgColumn Incompatible

Open oRafael07 opened this issue 1 year ago • 15 comments

Report hasn't been filed before.

  • [x] I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.43.1

What version of drizzle-kit are you using?

0.31.1

Other packages

No response

Describe the Bug

When I do the left Join on my accounts table, the typoscript complains about incompatibility

Image

My tables:

export const providerEnum = pgEnum('providers', ['google'])

const account = pgTable('accounts', {
  id: uuid('id').primaryKey().notNull().defaultRandom(),
  userId: uuid('user_id')
    .notNull()
    .references(() => users.id),
  provider: providerEnum().notNull(),
  providerId: text().notNull().unique(),
})

const users = pgTable('users', {
  id: uuid('id').primaryKey().defaultRandom(),
  name: text('name').notNull(),
  username: text('username').notNull().unique(),
  email: text('email').notNull().unique(),
  password: text('password'),
  createdAt: timestamp('created_at', { withTimezone: true })
    .defaultNow()
    .notNull(),
  updatedAt: timestamp('updated_at', { withTimezone: true }).$onUpdateFn(
    () => new Date()
  ),
})

My code:

const [userExists] = await db
  .select()
  .from(users)
  .where(eq(users.email, email))
  .innerJoin(account, eq(users.id, account.id))

Error:

Argument of type 'PgTableWithColumns<{ name: "accounts"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "accounts"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; ... 6 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; provider: PgCol...' is not assignable to parameter of type 'SQL<unknown> | Subquery<string, Record<string, unknown>> | PgViewBase<string, boolean, ColumnsSelection> | PgTable<TableConfig>'.
  Type 'PgTableWithColumns<{ name: "accounts"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "accounts"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; ... 6 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; provider: PgCol...' is not assignable to type 'PgTable<TableConfig>'.
    The types of '_.config.columns' are incompatible between these types.
      Type '{ id: PgColumn<{ name: "id"; tableName: "accounts"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; provider: PgColumn<...>; providerId: P...' is not assignable to type 'Record<string, PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>>'.
        Property 'id' is incompatible with index signature.
          Type 'PgColumn<{ name: "id"; tableName: "accounts"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>' is not assignable to type 'PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>'.
            The types of 'table._.config.columns' are incompatible between these types.
              Type 'Record<string, import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/pg-core/columns/common").PgColumn<import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/column").ColumnBaseConfig<import("d:/Projects/backend/santuario-sao-jose-operatio-backend/...' is not assignable to type 'Record<string, import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "import" } }).PgColumn<import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/column", { with: { "resolution-mode": "import" ...'.
                'string' index signatures are incompatible.
                  Type 'import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/pg-core/columns/common").PgColumn<import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/column").ColumnBaseConfig<import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/dr...' is not assignable to type 'import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "import" } }).PgColumn<import("d:/Projects/backend/santuario-sao-jose-operatio-backend/node_modules/drizzle-orm/column", { with: { "resolution-mode": "import" } }).ColumnBase...'.
                    Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.

oRafael07 avatar May 20 '25 04:05 oRafael07

Having the same issue. I use Turborepo, and i get errors like this in my packages/db folder but not in one of my apps/myapp folder. And only one single app in my turborepo has that problem aswell.

Argument of type 'PgTableWithColumns<{ name: "user_organization_group"; schema: "app"; columns: { orgId: PgColumn<{ name: "org_id"; tableName: "user_organization_group"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; ... 8 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; groupId: PgColu...' is not assignable to parameter of type 'SQL<unknown> | Subquery<string, Record<string, unknown>> | PgViewBase<string, boolean, ColumnsSelection> | PgTable<TableConfig>'.
  Type 'PgTableWithColumns<{ name: "user_organization_group"; schema: "app"; columns: { orgId: PgColumn<{ name: "org_id"; tableName: "user_organization_group"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; ... 8 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; groupId: PgColu...' is not assignable to type 'PgTable<TableConfig>'.
    The types of '_.config.columns' are incompatible between these types.
      Type '{ orgId: PgColumn<{ name: "org_id"; tableName: "user_organization_group"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; ... 5 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; groupId: PgColumn<...>; addedBy: PgCol...' is not assignable to type 'Record<string, PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>>'.
        Property 'orgId' is incompatible with index signature.
          Type 'PgColumn<{ name: "org_id"; tableName: "user_organization_group"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; ... 5 more ...; generated: undefined; }, {}, {}>' is not assignable to type 'PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>'.
            The types of 'table._.config.columns' are incompatible between these types.
              Type 'Record<string, import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/pg-core/columns/common").PgColumn<import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/column").ColumnBaseConfig<import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/column-b...' is not assignable to type 'Record<string, import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "import" } }).PgColumn<import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/column", { with: { "resolution-mode": "import" } }).ColumnBaseConfig<...'.
                'string' index signatures are incompatible.
                  Type 'import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/pg-core/columns/common").PgColumn<import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/column").ColumnBaseConfig<import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/column-builder").Column...' is not assignable to type 'import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "import" } }).PgColumn<import("/home/thaun/Documents/Projects/case-frontend/node_modules/drizzle-orm/column", { with: { "resolution-mode": "import" } }).ColumnBaseConfig<import("/home/t...'.
                    Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.

ThomasAunvik avatar May 20 '25 08:05 ThomasAunvik

Bug seems to be present since 0.43.0

Downgrading to 0.42.0 fixes the issue.

ThomasAunvik avatar May 20 '25 08:05 ThomasAunvik

Duplicate of issue https://github.com/drizzle-team/drizzle-orm/issues/4457

ThomasAunvik avatar May 20 '25 08:05 ThomasAunvik

Downgrading does not seem to fix the issue for me

ESchouten avatar May 20 '25 17:05 ESchouten

Same issue here, in a Nx monorepo.

lwensveen avatar May 30 '25 17:05 lwensveen

@oRafael07 Were you able to find a solution for this, thanks.

darahask avatar Jun 01 '25 16:06 darahask

@oRafael07 Were you able to find a solution for this, thanks.

Yeah, like said before, downgrade to 0.42, hasn't that worked for you?

lwensveen avatar Jun 01 '25 16:06 lwensveen

@oRafael07 do you have a monorepo setup?

AndriiSherman avatar Jun 03 '25 13:06 AndriiSherman

reproduced, fixing this issue at least trying

AndriiSherman avatar Jun 03 '25 13:06 AndriiSherman

@AndriiSherman I have currently downgraded to version 0.42.x

oRafael07 avatar Jun 03 '25 14:06 oRafael07

@oRafael07 do you have a monorepo setup?

No

oRafael07 avatar Jun 03 '25 14:06 oRafael07

The problem persists in version 0.44.1. The version 0.42.0 is a stable version for this problem.

leandromatos avatar Jun 03 '25 16:06 leandromatos

The problem persists in version 0.44.1. The version 0.42.0 is a stable version for this problem.

Yeah I can confirm this, it also doesn't matter if you're running a monorepo or not. I checked my nom packages to see if there were any version mismatches being pulled in somewhere through drizzle zod or something, but that wasn't the case. It's purely 0.42.0 => that's causing this.

lwensveen avatar Jun 03 '25 16:06 lwensveen

should be fixed in [email protected] Deploy is in progress, ~20 mins to go live

AndriiSherman avatar Jun 04 '25 06:06 AndriiSherman

fixed in [email protected]

AndriiSherman avatar Jun 04 '25 07:06 AndriiSherman