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.
4 Replies
rphlmr ⚡
rphlmr ⚡2mo ago
Yes, that's the fix! The pull could be improved, but what you have done is correct.
rphlmr ⚡
rphlmr ⚡2mo 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.
ijohnston
ijohnstonOP3w ago
@rphlmr ⚡ Thanks. That fixed the schema.ts file. Another question The github example repo does not contain a relations.ts file. In my project the relations.ts contains this: import { usersInAuth, notifications, notificationChannels, notificationTypeNotificationChannel, notificationTypes, userNotificationPreferences, schoolNotificationInstructions, schools, usersExt, subsTeacherRequests, roles, joinCodes, schoolUserRoles, scheduledNotifications, invites, organizationSettings } from "./schema"; The usersInAuth has this error: Module '"./schema"' has no exported member 'usersInAuth'.ts(2305) Two Options To Fix. Which is correct, or is there a better option? I have had a terribly hard time getting the pull and then generate to work 1. I import the predefined members like i did in the schema.ts file to the relations.ts:
import {
authenticatedRole,
authUid,
authUsers,
realtimeMessages,
realtimeTopic,
supabaseAuthAdminRole,
} from "drizzle-orm/supabase";
import {
authenticatedRole,
authUid,
authUsers,
realtimeMessages,
realtimeTopic,
supabaseAuthAdminRole,
} from "drizzle-orm/supabase";
2. I create another authSchema file that defines usersInAuth as detailed here and import that: https://www.reddit.com/r/Supabase/comments/1d8yse0/comment/l7c64km/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
Reddit
paddyjoneill's comment on "Drizzle Introspect"
Explore this conversation and more from the Supabase community
rphlmr ⚡
rphlmr ⚡3w ago
what is usersInAuth? But do answer, yes you can re import again from /supabase if it is authUsers. These imports are just here to be used as references in schema/relations
Want results from more Discord servers?
Add your server