drizzle-orm
drizzle-orm copied to clipboard
Validate TS schema with Drizzle Kit
Addresses #272.
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:
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
ExtraConfigColumnclass located atdrizzle-orm/src/pg-core/columns/common.ts.