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

Can't reference capitalized types in export to Postgresql #545

Open
jason-curtis opened this issue Apr 10, 2024 · 1 comment
Open

Can't reference capitalized types in export to Postgresql #545

jason-curtis opened this issue Apr 10, 2024 · 1 comment

Comments

@jason-curtis
Copy link

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!

@gguy0406
Copy link

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"

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

No branches or pull requests

2 participants