We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
drizzle-orm
0.33.0
drizzle-kit
0.24.2
Defining tables with foreign keys to each other causes drizzle-kit to output schema that does not type-check.
The following postgres schema:
create schema drizzle_test; create table drizzle_test.child ( id uuid primary key default uuid_generate_v4(), other_id uuid not null ); create table drizzle_test.parent ( id uuid primary key default uuid_generate_v4(), other_id uuid not null, child_id uuid unique references drizzle_test.child (id) on delete restrict, unique (other_id, child_id) ); alter table drizzle_test.child add constraint test_key foreign key (other_id, id) references drizzle_test.parent (other_id, child_id);
generates the following schema from introspection:
import { sql } from "drizzle-orm"; import { foreignKey, pgSchema, pgTable, unique, uuid, type AnyPgColumn } from "drizzle-orm/pg-core"; export const drizzleTest = pgSchema("drizzle_test"); export const childInDrizzleTest = drizzleTest.table( "child", { id: uuid("id") .default(sql`uuid_generate_v4()`) .primaryKey() .notNull(), parentId: uuid("parent_id").notNull(), }, (table) => { return { testKey: foreignKey({ columns: [table.parentId], foreignColumns: [parentInDrizzleTest.id], name: "test_key", }), }; }, ); export const parentInDrizzleTest = drizzleTest.table( "parent", { id: uuid("id") .default(sql`uuid_generate_v4()`) .primaryKey() .notNull(), childId: uuid("child_id"), }, (table) => { return { parentChildIdFkey: foreignKey({ columns: [table.childId], foreignColumns: [childInDrizzleTest.id], name: "parent_child_id_fkey", }), parentChildIdKey: unique("parent_child_id_key").on(table.childId), }; }, );
This fails to type-check due to the table definitions referencing each other in the extraConfig function.
extraConfig
Either introspect generates correct schema, or introspect does not generate foreign keys that would cause reference loops.
In addition, documentation on how to handle this when defining schema would be welcome.
System: OS: macOS 15.0 CPU: (10) arm64 Apple M1 Pro Memory: 117.55 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.13.1 - ~/.asdf/installs/nodejs/20.13.1/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 10.5.2 - ~/.asdf/plugins/nodejs/shims/npm pnpm: 9.7.0 - ~/.asdf/shims/pnpm npmPackages: drizzle-kit: ^0.24.2 => 0.24.2 drizzle-orm: ^0.33.0 => 0.33.0
The text was updated successfully, but these errors were encountered:
Facing same issue! It was working on previous versions... :'(
Sorry, something went wrong.
No branches or pull requests
What version of
drizzle-orm
are you using?0.33.0
What version of
drizzle-kit
are you using?0.24.2
Describe the Bug
Defining tables with foreign keys to each other causes drizzle-kit to output schema that does not type-check.
The following postgres schema:
generates the following schema from introspection:
This fails to type-check due to the table definitions referencing each other in the
extraConfig
function.Expected behavior
Either introspect generates correct schema, or introspect does not generate foreign keys that would cause reference loops.
In addition, documentation on how to handle this when defining schema would be welcome.
Environment & setup
The text was updated successfully, but these errors were encountered: