Joey9
Joey9
DTDrizzle Team
Created by Joey9 on 4/12/2025 in #help
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
24 replies