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

Validate TS schema with Drizzle Kit #3043

Open
wants to merge 14 commits into
base: beta
Choose a base branch
from

Conversation

L-Mario564
Copy link
Collaborator

@L-Mario564 L-Mario564 commented Oct 3, 2024

Addresses #272, #1031, #1766, #2667, #3325 and #2802.

This PR adds checks/validations for your Typescript schema for any dialect. This validation occurs during the generate and push commands in Drizzle Kit, giving detailed errors as to what went wrong and how you can fix them. If no errors were found, it will continue executing the respective command, otherwise it will stop execution and you'll have to fix those errors.

An example of what running a command that includes this validation looks like:
Screenshot_2024-10-02_103934

The following checks are performed:

  • Schema has a unique name (PG).
  • Entity (entity = table, view, materialized view, enum, sequence) has a unique name within the schema.
  • Constraint and index (primary key, foreign key, check, unique, index, unique index) has a unique name within the schema.
  • Values in an enum are unique (PG).
  • Sequence has valid values. This includes checking for an invalid increment, min and max value.
  • Columns have a unique name within each table. This also takes into account implicit and explicit column aliases.
  • Columns in a primary key belong to the same table.
  • The amount of columns in a foreign key match the amount of columns that it references.
  • Foreign key's columns and referenced columns have have the same data types.
  • Columns in a foreign key belongs to the same table.
  • Referenced columns in a foreign key belongs to the same table.
  • Whether the index requires a manually defined name (PG).
  • Vector type column in an index has an operator class (PG).

Misc. notes:

  • Fixed an infinitely recursive method in the ExtraConfigColumn class located at drizzle-orm/src/pg-core/columns/common.ts.

@L-Mario564 L-Mario564 changed the base branch from main to beta October 3, 2024 16:54
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

Successfully merging this pull request may close these issues.

1 participant