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
23.49k stars 577 forks source link

[BUG]: Missing `index names` when running `introspect` command [MYSQL] #2525

Closed pedro757 closed 1 month ago

pedro757 commented 3 months ago

What version of drizzle-orm are you using?

0.31.2

What version of drizzle-kit are you using?

0.22.6

Describe the Bug

I ran introspect command but It doesn't get index names

export const _TableToOtherTable = mysqlTable(
  "_TableToOtherTable",
  {
    A: int("A")
      .notNull()
      .references(() => Table.id, {
        onDelete: "cascade",
        onUpdate: "cascade",
      }),
    B: int("B")
      .notNull()
      .references(() => OtherTable.id, {
        onDelete: "cascade",
        onUpdate: "cascade",
      }),
  },
  table => {
    return {
      B_idx: index().on(table.B), //// Missing name here
      _TableToOtherTable_AB_unique: unique(
        "_TableToOtherTable_AB_unique",
      ).on(table.A, table.B),
    };
  },
);

Expected behavior

I expected to get the index name

_TableToOtherTable_B_index

Environment & setup

mysql v8.0.32

AndriiSherman commented 1 month ago

This should be fixed in drizzle-kit@0.24.1 If you still encounter this issue, please reopen the ticket

pedro757 commented 1 month ago

Still an issue in drizzle-kit@0.24.1 @AndriiSherman

BTW, I can't reopen the issue

AndriiSherman commented 1 month ago

Still an issue in drizzle-kit@0.24.1 @AndriiSherman

BTW, I can't reopen the issue

can you send me a create statement for your table, so I can reproduce it. Because running tests on names for indexes on introspect was working well for me

pedro757 commented 1 month ago

@AndriiSherman

CREATE TABLE `Entity` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=385 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `EntityTag` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `_EntityToEntityTag` (
  `A` int NOT NULL,
  `B` int NOT NULL,
  UNIQUE KEY `_EntityToEntityTag_AB_unique` (`A`,`B`),
  KEY `_EntityToEntityTag_B_index` (`B`),
  CONSTRAINT `_EntityToEntityTag_A_fkey` FOREIGN KEY (`A`) REFERENCES `Entity` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `_EntityToEntityTag_B_fkey` FOREIGN KEY (`B`) REFERENCES `EntityTag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

outputs

import { mysqlTable, mysqlSchema, AnyMySqlColumn, primaryKey, int, varchar, index, foreignKey, unique } from "drizzle-orm/mysql-core"
import { sql } from "drizzle-orm"

export const entity = mysqlTable("Entity", {
    id: int("id").autoincrement().notNull(),
    name: varchar("name", { length: 191 }).notNull(),
},
(table) => {
    return {
        entityId: primaryKey({ columns: [table.id], name: "Entity_id"}),
    }
});

export const entityTag = mysqlTable("EntityTag", {
    id: int("id").autoincrement().notNull(),
    name: varchar("name", { length: 191 }).notNull(),
},
(table) => {
    return {
        entityTagId: primaryKey({ columns: [table.id], name: "EntityTag_id"}),
    }
});

export const entityToEntityTag = mysqlTable("_EntityToEntityTag", {
    a: int("A").notNull().references(() => entity.id, { onDelete: "cascade", onUpdate: "cascade" } ),
    b: int("B").notNull().references(() => entityTag.id, { onDelete: "cascade", onUpdate: "cascade" } ),
},
(table) => {
    return {
        bIdx: index().on(table.b),
        entityToEntityTagAbUnique: unique("_EntityToEntityTag_AB_unique").on(table.a, table.b),
    }
});

No index names

john-griffin commented 1 month ago

Also not working for us in 0.24.1

mikker commented 2 days ago

Seeing this as well, 0.24.2