drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.61k stars 649 forks source link

[BUG]: Instrospect doesn't put `.primaryKey()` in my tables #3552

Open pedro757 opened 1 week ago

pedro757 commented 1 week ago

Report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.2

What version of drizzle-kit are you using?

0.28.1

Other packages

No response

Describe the Bug

This is what I get from an instrospect mysql database

export const Declaracion = mysqlTable("Declaracion", {
  id: int().autoincrement().notNull(),
  fecha: date({ mode: 'date' }).notNull(),
  empresaId: int().notNull().references(() => Empresa.id, { onDelete: "cascade", onUpdate: "cascade" } ),
},
(table) => {
  return {
    declaracionId: primaryKey({ columns: [table.id], name: "Declaracion_id"}),
  }
});

See what I mean in diff mode .primaryKey() is missing, however it recognizes the primarykey

export const Declaracion = mysqlTable("Declaracion", {
-  id: int().autoincrement().notNull().primaryKey(), // SHOULD GENERATE .primaryKey()
+  id: int().autoincrement().notNull(), // MISSING .primaryKey()
  fecha: date({ mode: 'date' }).notNull(),
  empresaId: int().notNull().references(() => Empresa.id, { onDelete: "cascade", onUpdate: "cascade" } ),
},
(table) => {
  return {
    declaracionId: primaryKey({ columns: [table.id], name: "Declaracion_id"}),
  }
});