Skip to content

Incorrect Example for Defining Composite Primary Keys #456

@farhadham

Description

@farhadham

The current documentation on the Drizzle ORM website provides an incorrect example for defining composite primary keys for postgreSQL using the primaryKey operator. Specifically, the example adds the primaryKey definitions inside an object with keys pk and pkWithCustomName, which does not align with the correct syntax.

Current Example:

export const booksToAuthors = pgTable("books_to_authors", {
  authorId: integer("author_id"),
  bookId: integer("book_id"),
}, (table) => {
  return [{
    pk: primaryKey({ columns: [table.bookId, table.authorId] }),
    pkWithCustomName: primaryKey({ name: 'custom_name', columns: [table.bookId, table.authorId] }),
  }];
});

Expected Example (Correct):

export const booksToAuthors = pgTable(
  "books_to_authors",
  {
    authorId: integer("author_id"),
    bookId: integer("book_id"),
  },
  (table) => {
    return [
      primaryKey({ columns: [table.bookId, table.authorId] }),
      primaryKey({ name: "custom_name", columns: [table.bookId, table.authorId] }),
    ];
  },
);

The current example may mislead developers into defining composite primary keys incorrectly, resulting in potential runtime errors or unexpected behavior when working with Drizzle ORM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions