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

[FEATURE]: Add schema enums to pg #669

Closed
maaasyn opened this issue May 31, 2023 · 4 comments · May be fixed by dennis-adrian/glitter-nextjs#87
Closed

[FEATURE]: Add schema enums to pg #669

maaasyn opened this issue May 31, 2023 · 4 comments · May be fixed by dennis-adrian/glitter-nextjs#87
Labels
enhancement New feature or request

Comments

@maaasyn
Copy link

maaasyn commented May 31, 2023

Describe want to want

Hey. Currently I'm trying to make my enum available only to the certain schema.

import { pgSchema, pgEnum } from "drizzle-orm/pg-core";

export const publicSchema = pgSchema("public");
export const differentSchema = pgSchema("different_schema");

// ✅ As expected I'm able to create table on different schema
export const publicTable = differentSchema.table("some_table", {
  id: varchar("id", { length: 36 }).primaryKey().notNull(),
});

// ✅ This works, it's available to public
export const abcEnum = pgEnum("ENUM", ["A", "B", "C"]);

// ❌ This syntax doesn't exist, but will fix my issue.
export const zyxEnum = differentSchema.enum("DIFFERENT_ENUM", ["Z", "Y", "X"]);

I will expect it to create:

CREATE TYPE "different_schema"."DIFFERENT_ENUM" AS ENUM ('Z', 'Y', 'X');
@maaasyn maaasyn added the enhancement New feature or request label May 31, 2023
@aflatoon2874
Copy link

Any timeline to include this much needed feature. We are unable to use drizzle for multi-tenant use cases.

@rtkevin
Copy link

rtkevin commented Aug 23, 2023

hacky solution (prefix name with schema):

export const sandboxTextEnum = pgEnum('test"."sandbox_text_enum', ['a', 'b', 'c']);

works except array type starts with _

select t.typnamespace,n.nspname,t.oid,t.typname,t.typarray,t.typsend from pg_type t left join pg_namespace n on n.oid=t.typnamespace where t.typname like '%sandbox%' order by t.typnamespace,t.typname;
 typnamespace | nspname |  oid  |      typname       | typarray |  typsend
--------------+---------+-------+--------------------+----------+------------
        35160 | test    | 35161 | _sandbox_int_enum  |        0 | array_send
        35160 | test    | 35171 | _sandbox_text_enum |        0 | array_send
        35160 | test    | 35162 | sandbox_int_enum   |    35161 | enum_send
        35160 | test    | 35172 | sandbox_text_enum  |    35171 | enum_send
(4 rows)

so get ERROR: type "test.sandbox_text_enum[]" does not exist if you make such an enum array column

@dankochetov
Copy link
Contributor

The ORM part is now available in drizzle-orm@beta. Support in drizzle-kit is still pending, so it won't generate migrations for such enums, but you can create custom migrations to work around it for now.

@cmanou
Copy link

cmanou commented Apr 23, 2024

@dankochetov Any updates on the drizzle kit support? Happy to help implement if drizzle kit gets open sourced like planned.

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

Successfully merging a pull request may close this issue.

5 participants