Skip to content

No support for Drizzle ORM multi-column foreign keys #4045

@g30r93g

Description

@g30r93g

Self Checks

Version Type

CLI Version (npm package)

Version (only for Self Hosted)

No response

Steps to reproduce

  1. Create a Drizzle ORM schema that uses foreignKey instead of .references()
import { primaryKey, serial, foreignKey, pgTable, text } from "drizzle-orm/pg-core";

export const user = pgTable("user", {
  firstName: text("firstName"),
  lastName: text("lastName"),
}, (table) => [
  primaryKey({ columns: [table.firstName, table.lastName]})
]);
export const profile = pgTable("profile", {
  id: serial("id").primaryKey(),
  userFirstName: text("user_first_name"),
  userLastName: text("user_last_name"),
}, (table) => [
  foreignKey({
    columns: [table.userFirstName, table.userLastName],
    foreignColumns: [user.firstName, user.lastName],
    name: "custom_fk"
  })
]);
  1. Run npx @liam-hq/cli erd build --format drizzle --input ./db/sample-schema.ts
  2. Observe lack of crows feet denoting relations, and missing relationship properties Image

It also seems to miss the composite primary key in the user table.

Expected Behavior

  1. Detect usage of operators such as foreignKey, primaryKey
  2. Apply logic as it otherwise would for .references()

Actual Behavior

No acknowledgement of foreignKey or primaryKey operators

Additional Context

https://orm.drizzle.team/docs/indexes-constraints#foreign-key

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions