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

PostgreSQL: id uuid primary key is in OptionalAttributes #572

Closed
honzajerabek opened this issue Dec 1, 2021 · 2 comments
Closed

PostgreSQL: id uuid primary key is in OptionalAttributes #572

honzajerabek opened this issue Dec 1, 2021 · 2 comments

Comments

@honzajerabek
Copy link
Contributor

Hi, having an id PK uuid column of a table (example) makes an id creation attribute type to be optional. I still have to pass generated uuid v4 when creating though.

CREATE TABLE test (
  id                  uuid primary key,
  created_at   timestamp without time zone NOT NULL,
  updated_at  timestamp without time zone,
  deleted_at   timestamp without time zone
);

results in id in TestOptionalAttributes.

export interface TestAttributes {
  id: string;
  createdAt: Date;
  updatedAt?: Date;
  deletedAt?: Date;
}

export type TestPk = "id";
export type TestId = Test[TestPk];
export type TestOptionalAttributes = "id" | "updatedAt" | "deletedAt";
export type TestCreationAttributes = Optional<TestAttributes, TestOptionalAttributes>;

When I'm not providing the optional id when creating the entity, I'm getting the notNull Violation: Test.id cannot be null

This has probably something to do with acd67f6 I see that any fieldObj.primaryKey field is considered as optional

@honzajerabek
Copy link
Contributor Author

Hmm I believe this might be actually fixed in #547

@steveschmitt
Copy link
Collaborator

Fixed in [email protected]

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