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]: Migrations are not generated for new Indexes #3873

Closed
1 task done
dead8309 opened this issue Dec 30, 2024 · 2 comments
Closed
1 task done

[BUG]: Migrations are not generated for new Indexes #3873

dead8309 opened this issue Dec 30, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@dead8309
Copy link

dead8309 commented Dec 30, 2024

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.4

What version of drizzle-kit are you using?

0.30.1

Other packages

No response

Describe the Bug

Creating a new issue for #3857 as the op closed that one.

The new way of describing tables properties(i.e. returning an array of object) doesn't create migrations file If the constraints are added later

This does't work

export const pageChunks = pgTable(
  "page_chunks",
  {
    id: serial("id").primaryKey(),
    content: text("content").notNull(),
    embedding: vector("embedding", { dimensions: 1024 }),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    updatedAt: timestamp("updated_at").defaultNow().notNull(),
  },
  (table) => [
    {
      embeddingIdx: index("embedding_idx").using(
        "hnsw",
        table.embedding.op("vector_cosine_ops")
      ),
    },
  ]
);

but if we use deprecated signature it works fine.

export const pageChunks = pgTable(
  "page_chunks",
  {
    id: serial("id").primaryKey(),
    content: text("content").notNull(),
    embedding: vector("embedding", { dimensions: 1024 }),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    updatedAt: timestamp("updated_at").defaultNow().notNull(),
  },
  (table) => ({
    embeddingIdx: index("embedding_idx").using(
      "hnsw",
      table.embedding.op("vector_cosine_ops")
    ),
  })
);
@dead8309 dead8309 added the bug Something isn't working label Dec 30, 2024
dead8309 added a commit to dead8309/ai-rag-crawler that referenced this issue Dec 30, 2024
@AdamAkiva
Copy link

I've encountered this issue in the past.
The issue that you have it that you return an array of objects.
It should return an array of indexes (In your case).
E.g, you should change:

(table) => [
    {
      embeddingIdx: index("embedding_idx").using(
        "hnsw",
        table.embedding.op("vector_cosine_ops")
      ),
    },
  ]

to:

(table) => [
       index("embedding_idx").using(
        "hnsw",
        table.embedding.op("vector_cosine_ops")
      ),
  ]

I've checked this locally with the same drizzle & drizzle-kit versions you've supplied and this is the generated SQL (attached only the index part):

CREATE INDEX "embedding_idx" ON "page_chunks" USING hnsw ("embedding" vector_cosine_ops);--> statement-breakpoint

Hope this resolves your issue

@dead8309
Copy link
Author

Thanks @AdamAkiva that worked!

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

2 participants