dbml icon indicating copy to clipboard operation
dbml copied to clipboard

Can't reference capitalized types in export to Postgresql

Open jason-curtis opened this issue 1 year ago • 1 comments

Problem

If there is an enum with capital letters in its name, the .sql export is broken such that the enum can't be referenced (or else I haven't been able to figure out how).

Example

Take an example DBML file:

Enum UserRole{
  "Super Admin"
  "Super Ultra Admin"
}

Table User {
  role UserRole
  ...
}

When I convert that to Postgresql, it looks like:

CREATE TYPE "UserRole" AS ENUM (
  'Super Admin',
  'Super Duper Admin'
);

CREATE TABLE "User" (
  "role" UserRole
)

This seems fine except that SQL loves to ignore capitalization, so upon running the .sql I get ERROR: type "userrole" does not exist. The correct .sql output would have the enum type quoted to reference it correctly:

CREATE TABLE "User" (
  "role" "UserRole"
  ...
)

Attempted workaround

If you use quotes in the DBML like so, you might expect those quotes to carry through to the .sql file:

Table User {
  role "UserRole"
  ...
}

but the above DBML generates the same unquoted SQL, causing the same problem as earlier.

Apologies for the edge case!

jason-curtis avatar Apr 10 '24 22:04 jason-curtis

This doesn't work with normalized enum name as well. In my case, the dbml look like this:

Enum user.gender {
  ...
}

Table user.user {
  ...
  gender user.gender [not null]
}

And the exported PostgreSQL as follow:

CREATE TABLE "user"."user" (
  ...
  "gender" user.gender NOT NULL,
)

which output syntax error at or near "user"

gguy0406 avatar Jul 16 '24 02:07 gguy0406

Fixed in https://github.com/holistics/dbml/pull/735

NQPhuc avatar Jun 19 '25 07:06 NQPhuc