Skip to content

[BUG]:Drizzle & Supabase AuthUsers #4405

Open
@Anonymous2416

Description

@Anonymous2416

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.41.0

What version of drizzle-kit are you using?

0.30.6

Other packages

No response

Describe the Bug

Hello, im using supabase and doing a database first approach. I make my db changes using supabase UI and then i drizzle-kit pull to generate the ts files.

right now doing the command its making

import { pgTable, foreignKey, unique, pgPolicy, uuid, text, timestamp } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"



export const users = pgTable("users", {
    id: uuid().primaryKey().notNull(),
    first_name: text(),
    last_name: text(),
    username: text(),
    avatar_url: text(),
    created_at: timestamp({ withTimezone: true, mode: 'string' }).defaultNow().notNull(),
    email: text().notNull(),
}, (table) => [
    foreignKey({
            columns: [table.id],
            foreignColumns: [table.id],
            name: "users_id_fkey"
        }).onDelete("cascade"),
    unique("users_username_key").on(table.username),
    pgPolicy("Users can update their own users table", { as: "permissive", for: "update", to: ["public"], using: sql`(( SELECT auth.uid() AS uid) = id)` }),
    pgPolicy("Enable read access for all users", { as: "permissive", for: "select", to: ["public"] }),
    pgPolicy("Enable insert for users based on id", { as: "permissive", for: "insert", to: ["public"] }),
]);

and

import { relations } from "drizzle-orm/relations";
import { usersInAuth, users } from "./schema";

export const usersRelations = relations(users, ({one}) => ({
    usersInAuth: one(usersInAuth, {
        fields: [users.id],
        references: [usersInAuth.id]
    }),
}));

export const usersInAuthRelations = relations(usersInAuth, ({many}) => ({
    users: many(users),
}));

the usersInAuth doesn't exists and i saw looking through discord we import from:
import { authUsers } from "drizzle-orm/supabase" to make it work.
But how can i make drizzle use that, because whenever i drizzle-kit pull, its just going to keep overwriting the relation,schema ts files

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions