DT
Drizzle Team•2w ago
Joey9

Drizzle & Supabase

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"] }),
]);
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),
}));
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 any help/advice when working with supabase would be appreciated. thanks
15 Replies
Joey9
Joey9OP•7d ago
anyone? bump @Mario564 is this a bug? is there anything i can do?
Mario564
Mario564•7d ago
This definitely seems like an oversight on our part. Could you please submit an issue on Github to track this issue? We may not be able to immediately fix it as Kit is underdoing a rewrite, but we'll try to address it as soon as that's done
Joey9
Joey9OP•7d ago
yea i did: https://github.com/drizzle-team/drizzle-orm/issues/4405 is there anything i can do in the meantime 😦
Mario564
Mario564•7d ago
Not much for now, aside from manually including the import or making script that adds that line
Joey9
Joey9OP•7d ago
Alright... thanks for the answer is this another bug? i made an issue for it just in case since im not sure. https://github.com/drizzle-team/drizzle-orm/issues/4407
Mario564
Mario564•6d ago
It likely is a bug
Joey9
Joey9OP•6d ago
😢 this not looking good, might have to just end up using supabase orm... do you have any advice since theres quite a few issues right now? i really wanted to use drizzle but idk what to do now..
Mario564
Mario564•6d ago
I think the best coures of action right now is adding your own script that patches up the issues you may encounter with introspection. Aside from some Kit issues, the ORM itself is very stable and definitely worth a shot
Joey9
Joey9OP•6d ago
alright, thank you. I know its impossible to give timeframes, but do you have a best estimate on when these things(with supabase specifically) will become more stable?
Mario564
Mario564•6d ago
Don't have an ETA since there's implementing these fixes, reviewing them and then shipping them to a release, which all might have variable amount of time to complete
Joey9
Joey9OP•6d ago
also since the issues seem to be mostly with introspection, would you recommend i do create the tables through code then push to supabase. so do a codebase first approach?
Mario564
Mario564•6d ago
That's also an alternative. Things should be a lot more stable in that regard
Joey9
Joey9OP•6d ago
alright, thanks again so much for the help
SAF
SAF•3d ago
There are so many small but breaking issues like this that I can't understand how anyone is using drizzle-kit and supabase seriously 🤔
Dragomir
Dragomir•6h ago
yes. There is no way to use it. Especially the Auth. Man, 3 days I am implementing stupid solutions for e-commerce cart sessions. Nextauth, Better auth and Supabase CANNOT make simple sessions with drizzle it's getting absurd If you want auth schema in drizzle you are screwed.

Did you find this page helpful?