refactor: reinstate drizzle

This commit is contained in:
Henry
2025-04-23 13:11:00 +01:00
parent 0c25fe3864
commit c1348cf455
22 changed files with 1964 additions and 879 deletions

View File

@@ -1,12 +1,5 @@
import { relations, sql } from "drizzle-orm";
import {
pgPolicy,
pgTable,
timestamp,
uuid,
varchar,
} from "drizzle-orm/pg-core";
import { authenticatedRole } from "drizzle-orm/supabase";
import { relations } from "drizzle-orm";
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
import { boards } from "./boards";
import { cards } from "./cards";
@@ -14,35 +7,14 @@ import { imports } from "./imports";
import { lists } from "./lists";
import { workspaceMembers, workspaces } from "./workspaces";
export const users = pgTable(
"user",
{
id: uuid("id").notNull().primaryKey(),
name: varchar("name", { length: 255 }),
email: varchar("email", { length: 255 }).notNull().unique(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: varchar("image", { length: 255 }),
stripeCustomerId: varchar("stripeCustomerId", { length: 255 }),
},
() => [
pgPolicy("Allow viewing members in user's workspace", {
for: "select",
as: "permissive",
to: [authenticatedRole],
using: sql`
id IN (
SELECT wm."userId"
FROM workspace_members wm
WHERE wm."workspaceId" IN (
SELECT "workspaceId"
FROM workspace_members
WHERE "userId" = auth.uid()
)
)
`,
}),
],
).enableRLS();
export const users = pgTable("user", {
id: uuid("id").notNull().primaryKey(),
name: varchar("name", { length: 255 }),
email: varchar("email", { length: 255 }).notNull().unique(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: varchar("image", { length: 255 }),
stripeCustomerId: varchar("stripeCustomerId", { length: 255 }),
}).enableRLS();
export const usersRelations = relations(users, ({ many }) => ({
boards: many(boards),