L-Mario564 / drizzle-dbml-generator

Generate DBML markup from your schema defined with Drizzle ORM.
MIT License
161 stars 8 forks source link

Breaking bug with multi-schema #18

Closed samburgers closed 2 months ago

samburgers commented 4 months ago

Hi, discovered a small but breaking issue with this schema:

const authSchema = pgSchema("auth");

export const User = authSchema.table("users", {
  id: uuid("id").notNull().primaryKey().defaultRandom(),
  email: text("email").notNull().unique(),
});

export const ProfileInfo = pgTable("profile_info", {
  id: uuid("id").notNull().primaryKey().defaultRandom(),
  userId: uuid("user_id")
    .references(() => User.id)
    .notNull()
    .unique(),
});

Which outputs this invalid dbml:

table profile_info {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id uuid [not null, unique]
}

table auth.users {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  email text [not null, unique]
}

ref profile_info_user_id_users_id_fk: profile_info.user_id > users.id [delete: no action, update: no action]

If i go and hand change the last line to this it validates fine

ref profile_info_user_id_users_id_fk: profile_info.user_id > auth.users.id [delete: no action, update: no action]

so just users.id needs to become auth.users.id

Many thanks!