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]: PostgreSQL Enum Naming and Schema Typing Issue #2315

Open
superBertBerg opened this issue May 14, 2024 · 0 comments
Open

[BUG]: PostgreSQL Enum Naming and Schema Typing Issue #2315

superBertBerg opened this issue May 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@superBertBerg
Copy link

superBertBerg commented May 14, 2024

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.1

Describe the Bug

This is the drizzle.config.ts:

import type { Config } from 'drizzle-kit';

export default {
  out: './src/orm',
  schemaFilter: [
    'public',
    'auth',
  ],
  introspect: {
    casing: 'camel',
  },
  dialect: 'postgresql',
  dbCredentials: {
    database: 'postgres',
    user: 'postgres',
    password: 'postgres',
    host: '0.0.0.0',
    port: 5432,
  },
} satisfies Config;

Description:

When an enum is defined in a schema other than 'public', Drizzle ORM names the enum as ${enumName}In${schemaName}. However, this naming convention is not consistently applied when tables are typed, regardless of whether they are in the same schema or a different one.

Steps to Reproduce:

  1. Create an enum in a schema other than 'public' using Drizzle ORM.
  2. Create a table which has a column with this enum.
  3. Generate the schema file using drizzle-kit introspect.
  4. Observe the inconsistency in the enum naming within the generated schema file.

Expected Behavior:

The generated schema should consistently use the ${enumName}In${schemaName} format for enums, ensuring that table definitions reference the correct enum type regardless of the schema they belong to.

Actual Behavior:

The generated schema file incorrectly references the enum type without the schema-specific naming convention, leading to potential type errors.

Example:

Given the following setup:

export const auth = pgSchema("auth");
export const aalLevelInAuth = auth.enum("aal_level", ['aal1', 'aal2', 'aal3']);

The generated table definition incorrectly references the enum as aalLevel instead of aalLevelInAuth:

export const sessionsInAuth = auth.table("sessions", {
  id: uuid("id").primaryKey().notNull(),
  userId: uuid("user_id").notNull().references(() => usersInAuth.id, { onDelete: "cascade" }),
  createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }),
  updatedAt: timestamp("updated_at", { withTimezone: true, mode: 'string' }),
  factorId: uuid("factor_id"),
  aal: aalLevel("aal"),  // This should be aalLevelInAuth("aal")
  notAfter: timestamp("not_after", { withTimezone: true, mode: 'string' }),
  refreshedAt: timestamp("refreshed_at", { mode: 'string' }),
  userAgent: text("user_agent"),
  ip: inet("ip"),
  tag: text("tag"),
});
@superBertBerg superBertBerg added the bug Something isn't working label May 14, 2024
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

1 participant