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

Workaround for column un-supported settings doesn't work #591

Open
gguy0406 opened this issue Jul 17, 2024 · 1 comment
Open

Workaround for column un-supported settings doesn't work #591

gguy0406 opened this issue Jul 17, 2024 · 1 comment

Comments

@gguy0406
Copy link

Problem

The workaround for un-supported settings by adding the setting name into the column type name, such as id “bigint unsigned” [pk] doesn't work

Example

Take an example DBML file:

Table Product {
  id integer [increment, pk]
  price "integer check (price > 0)" [not null]
  quantity "integer check(quantity > 0) [default: 0, not null]
}

When I convert that to Postgresql, it looks like:

CREATE TABLE "Product " (
  "id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  "price" "integer check (price > 0)" NOT NULL,
  "quantity" "integer check (quantity > 0)" NOT NULL DEFAULT 0,
);

Which then throwing error when attempting to execute query pq: type "integer check (totalPrice > 0)" does not exist

@NQPhuc
Copy link
Contributor

NQPhuc commented Jul 18, 2024

Hi,

Currently, there's no way to add check constraint and other unsupported settings so the the export SQL is correctly equivalent.

The work-around is only mean to make the dbml valid. Instead of putting the constraint in the column type, you can try to annotate the constraint in field note, like this:

Table Product {
  id integer [increment, pk]
  price integer [not null, note: "check (price > 0)"]
  quantity integer [default: 0, not null, note: "check (quantity > 0)"]
}

Which will export to Postgresql without error, but you'll have to add the check constraint back mannually.

We'll consider support the CHECK constraint in the future as well, since it is a common problem.

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