Skip to content

PostgreSQL: id uuid primary key is in OptionalAttributes #572

Description

@honzajerabek

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions