Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pedro757 opened this issue Jun 17, 2024 · 5 comments
Closed

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

pedro757 opened this issue Jun 17, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@pedro757
Copy link

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

@pedro757 pedro757 added the bug Something isn't working label Jun 17, 2024
@pedro757 pedro757 changed the title [BUG]: Doesn't get index names when running introspect command [MYSQL] [BUG]: Missing index names when running introspect command [MYSQL] Jun 17, 2024
@AndriiSherman
Copy link
Member

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

@pedro757
Copy link
Author

pedro757 commented Aug 22, 2024

Still an issue in drizzle-kit@0.24.1 @AndriiSherman

BTW, I can't reopen the issue

@AndriiSherman
Copy link
Member

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
Copy link
Author

pedro757 commented Aug 22, 2024

@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
Copy link

Also not working for us in 0.24.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants