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]: Creating index with using does not yield any result #817

Open
lvisb opened this issue Jun 26, 2023 · 4 comments
Open

[BUG]: Creating index with using does not yield any result #817

lvisb opened this issue Jun 26, 2023 · 4 comments
Assignees
Labels
drizzle-kit enhancement New feature or request

Comments

@lvisb
Copy link

lvisb commented Jun 26, 2023

What version of drizzle-orm are you using?

0.27.0

What version of drizzle-kit are you using?

0.19.1

Describe the Bug

  1. Create a schema with the following code:
export const user = pgTable(
  'users',
  {
    userId: serial('user_id').primaryKey(),
    meta: jsonb('meta').default({
      invite: {
        invited_at: null,
        accepted_at: null,
      },
    }),
  },
  (users) => ({
    metaIndex: index('meta_idx').on(users.meta).using(sql`GIN`),
  }),
)
  1. Generate the code for migration:
drizzle-kit generate:pg
  1. Inspect the generated migration and note that the result of the index creation is only this:
CREATE INDEX IF NOT EXISTS "meta_idx" ON "users" ("meta");

I hope this helps! Let me know if you need any further assistance.

Expected behavior

The expected result should be the creation of an index as shown below:

CREATE INDEX IF NOT EXISTS  "meta_idx" ON "users" USING GIN(meta jsonb_ops);

Also, it would be necessary to somehow optionally specify the jsonb_ops or jsonb_path_ops in the GIN index.

Environment & setup

No response

@lvisb lvisb added the bug Something isn't working label Jun 26, 2023
@StarpTech
Copy link

StarpTech commented Jul 16, 2023

I run into this limit as well. Would be great if we can add any kind of index.

@AndriiSherman AndriiSherman added enhancement New feature or request and removed bug Something isn't working labels Jul 21, 2023
@AndriiSherman
Copy link
Member

drizzle-kit currently can't read any options for indexes from drizzle-orm. But it's planned to be added in next drizzle-kit releases

@andersoncardoso
Copy link

@AndriiSherman I have a suggestion for cases like this, I guess that if we could somehow provide a scape hatch on the schema definition to append a sql string directly, that plays well with drizzle-kit migrations, this could solve many issues, including this one. Another example that would be solved is for having always generated as. For example:

export const user = pgTable(
  'users',
  {
    userId: serial('user_id').primaryKey(),
    meta: jsonb('meta').default({ ... }),
    otherField: text("other_field").sql(`GENERATED ALWAYS AS (...some expression...) STORED`)
  },
  (users) => ({
    metaIndex: index('meta_idx').on(users.meta).sql(`USING GIN(meta jsonb_ops)`),
  }),
)

I think that this fit well with drizzle's idea to embrace SQL ("if you know sql you know drizzle") and provides flexibility to the user. Nothing more natural than allowing them to pass sql to a schema for generating the migrations. Makes sense?

@warflash
Copy link

Just stumbled across this after a bit of research. By the looks of it advanced index creation is not working yet right? Any workarounds you guys might be able to share? Would be highly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drizzle-kit enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants