refactor: reinstate drizzle
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import { relations } from "drizzle-orm";
|
||||
import {
|
||||
bigserial,
|
||||
pgEnum,
|
||||
pgPolicy,
|
||||
pgTable,
|
||||
timestamp,
|
||||
uuid,
|
||||
varchar,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { authenticatedRole } from "drizzle-orm/supabase";
|
||||
|
||||
import { boards } from "./boards";
|
||||
import { cards } from "./cards";
|
||||
@@ -23,29 +21,16 @@ export const importStatusEnum = pgEnum("status", [
|
||||
"failed",
|
||||
]);
|
||||
|
||||
export const imports = pgTable(
|
||||
"import",
|
||||
{
|
||||
id: bigserial("id", { mode: "number" }).primaryKey(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
||||
source: importSourceEnum("source").notNull(),
|
||||
status: importStatusEnum("status").notNull(),
|
||||
createdBy: uuid("createdBy")
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
||||
},
|
||||
() => [
|
||||
pgPolicy("Allow access to user's own imports", {
|
||||
for: "all",
|
||||
as: "permissive",
|
||||
to: [authenticatedRole],
|
||||
using: sql`
|
||||
"createdBy" = auth.uid()
|
||||
`,
|
||||
}),
|
||||
],
|
||||
).enableRLS();
|
||||
export const imports = pgTable("import", {
|
||||
id: bigserial("id", { mode: "number" }).primaryKey(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
||||
source: importSourceEnum("source").notNull(),
|
||||
status: importStatusEnum("status").notNull(),
|
||||
createdBy: uuid("createdBy")
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
||||
}).enableRLS();
|
||||
|
||||
export const importsRelations = relations(imports, ({ one, many }) => ({
|
||||
createdBy: one(users, {
|
||||
|
||||
Reference in New Issue
Block a user