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]: Handling Postgresql schemas when using enums #2274

Closed
Entsllor opened this issue May 8, 2024 · 1 comment
Closed

[BUG]: Handling Postgresql schemas when using enums #2274

Entsllor opened this issue May 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Entsllor
Copy link

Entsllor commented May 8, 2024

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.20.18

Describe the Bug

Hello. I have a simple table with a status column

export const BaseSchema = pgSchema(settings.DB_SCHEMA_NAME); // DB_SCHEMA_NAME=my_schema
export const statusEnum = BaseSchema.enum("version_status", ['draft', 'published', 'inactive']);

export const versions = BaseSchema.table("versions", {
    status: statusEnum("status").default("draft"),
    // ...rest columns
});
// migration config
migrate(drizzle(migrationClient), {migrationsFolder: "src/migrations", migrationsSchema: "my_schema"})

// drizzle kit config
const config = {
    schema: "src/models",
    out: "src/migrations",
    driver: "pg",
    schemaFilter: "my_schema",
    dbCredentials: {
        connectionString: settings.DB_URL,
    },
    verbose: true,
    strict: true,
};

export default defineConfig(config);

New generated migration contains this:

DO $$ BEGIN
 CREATE TYPE "version_status" AS ENUM('draft', 'published', 'inactive');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;

But it does not consider DB_SCHEMA_NAME, and this type will be stored in public.object types instead of my_schema.object types

Expected behavior

I expect the migration to contain this:

DO $$ BEGIN
 CREATE TYPE "my_schema"."version_status" AS ENUM('draft', 'published', 'inactive');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;

(TYPE "my_schema"."version_status") instead of (TYPE "version_status")

Environment & setup

I use postgres.js, drizzle 0.30.10 and drizzle-kit 0.20.18

@Entsllor Entsllor added the bug Something isn't working label May 8, 2024
@AndriiSherman
Copy link
Member

Please try upgrading to latest drizzle-kit, it should handle enums as expected

https://orm.drizzle.team/kit-docs/upgrade-21

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