Can't migrate with pgPolicy and pgRoles

For context, this is my current setup, I cannot drizzle kit push to my schema and getthing an error saying: error: role "BODYSHOP_ADMIN" does not exist Roles.ts
export const bodyShopAdminRole = pgRole("BODYSHOP_ADMIN");
export const bodyShopMemberRole = pgRole("BODYSHOP_MEMBER");

export const bodyShopAdminAccessPolicy = (policyName: string) =>
pgPolicy(policyName, {
as: "permissive",
to: bodyShopAdminRole,
for: "all",
using: sql`body_shop_id = current_setting('app.current_bodyshop_id')::uuid`,
});

export const bodyShopMemberAccessPolicy = (policyName: string) =>
pgPolicy(policyName, {
as: "permissive",
to: bodyShopMemberRole,
for: "all",
using: sql`body_shop_id = current_setting('app.current_bodyshop_id')::uuid`,
});
export const bodyShopAdminRole = pgRole("BODYSHOP_ADMIN");
export const bodyShopMemberRole = pgRole("BODYSHOP_MEMBER");

export const bodyShopAdminAccessPolicy = (policyName: string) =>
pgPolicy(policyName, {
as: "permissive",
to: bodyShopAdminRole,
for: "all",
using: sql`body_shop_id = current_setting('app.current_bodyshop_id')::uuid`,
});

export const bodyShopMemberAccessPolicy = (policyName: string) =>
pgPolicy(policyName, {
as: "permissive",
to: bodyShopMemberRole,
for: "all",
using: sql`body_shop_id = current_setting('app.current_bodyshop_id')::uuid`,
});
export const customers = pgTable(
"customers",
{
id: uuid("id").primaryKey().defaultRandom(),
firstName: varchar("first_name"),
lastName: varchar("last_name"),
address1: varchar("address1"),
address2: varchar("address2"),
city: varchar("city"),
state: varchar("state"),
postcode: varchar("postcode"),
country: varchar("country"),
email: varchar("email"),
phone: varchar("phone"),
bodyShopId: uuid("body_shop_id")
.references(() => bodyShops.id, { onDelete: "cascade" })
.notNull(),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").default(defaultTimestamp.updatedAt()),
},
(_t) => [
bodyShopAdminAccessPolicy("bodyshop_admin_policy"),
bodyShopMemberAccessPolicy("bodyshop_member_policy"),
]
).enableRLS();
export const customers = pgTable(
"customers",
{
id: uuid("id").primaryKey().defaultRandom(),
firstName: varchar("first_name"),
lastName: varchar("last_name"),
address1: varchar("address1"),
address2: varchar("address2"),
city: varchar("city"),
state: varchar("state"),
postcode: varchar("postcode"),
country: varchar("country"),
email: varchar("email"),
phone: varchar("phone"),
bodyShopId: uuid("body_shop_id")
.references(() => bodyShops.id, { onDelete: "cascade" })
.notNull(),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").default(defaultTimestamp.updatedAt()),
},
(_t) => [
bodyShopAdminAccessPolicy("bodyshop_admin_policy"),
bodyShopMemberAccessPolicy("bodyshop_member_policy"),
]
).enableRLS();
drizzle.config.ts
export default defineConfig({
dialect: "postgresql",
schema: "./server/db/schema",
out: "./server/db/migrations",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
entities: {
roles: {
provider: "supabase",
include: ["BODYSHOP_ADMIN", "BODYSHOP_MEMBER"],
},
},
});
export default defineConfig({
dialect: "postgresql",
schema: "./server/db/schema",
out: "./server/db/migrations",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
entities: {
roles: {
provider: "supabase",
include: ["BODYSHOP_ADMIN", "BODYSHOP_MEMBER"],
},
},
});
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server