Supabase [users.id]

I ran drizzle-kit pull to get my existing schema from Supabase. The schema output included the following
export const notifications = pgTable("notifications", {
id: uuid().defaultRandom().primaryKey().notNull(),
userId: uuid("user_id").notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(),
body: text().notNull(),
}, (table) => {
return {
notificationsUserIdFkey: foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "notifications_user_id_fkey"
}),
}
});
export const notifications = pgTable("notifications", {
id: uuid().defaultRandom().primaryKey().notNull(),
userId: uuid("user_id").notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(),
body: text().notNull(),
}, (table) => {
return {
notificationsUserIdFkey: foreignKey({
columns: [table.userId],
foreignColumns: [users.id],
name: "notifications_user_id_fkey"
}),
}
});
The issue was with [users.id]. It said: Cannot find name 'users'.ts(2304). I updated [users.id] to be [authUsers.id]. I also imported:
import {
authenticatedRole,
authUid,
authUsers,
realtimeMessages,
realtimeTopic,
supabaseAuthAdminRole,
} from "drizzle-orm/supabase";
import {
authenticatedRole,
authUid,
authUsers,
realtimeMessages,
realtimeTopic,
supabaseAuthAdminRole,
} from "drizzle-orm/supabase";
Is that correct fix? The error went away, but this is all new to me.
2 Replies
rphlmr ⚡
rphlmr ⚡3w ago
Yes, that's the fix! The pull could be improved, but what you have done is correct.
rphlmr ⚡
rphlmr ⚡3w ago
GitHub
drizzle-supabase-rls/database/schema.ts at main · rphlmr/drizzle-su...
Contribute to rphlmr/drizzle-supabase-rls development by creating an account on GitHub.
Want results from more Discord servers?
Add your server