* feat: add account deletion functionality with cascade delete for workspace relations * fix: add cascade delete to workspace user foreign key constraints * fix: change onDelete action to set null for user references in schema * feat: tweak design --------- Co-authored-by: Henry <henry_ball@hotmail.co.uk> Co-authored-by: Henry <30578846+hjball@users.noreply.github.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { relations } from "drizzle-orm";
|
|
import {
|
|
bigint,
|
|
bigserial,
|
|
integer,
|
|
pgTable,
|
|
timestamp,
|
|
uuid,
|
|
varchar,
|
|
} from "drizzle-orm/pg-core";
|
|
|
|
import { boards } from "./boards";
|
|
import { cards } from "./cards";
|
|
import { imports } from "./imports";
|
|
import { users } from "./users";
|
|
|
|
export const lists = pgTable("list", {
|
|
id: bigserial("id", { mode: "number" }).primaryKey(),
|
|
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
|
name: varchar("name", { length: 255 }).notNull(),
|
|
index: integer("index").notNull(),
|
|
createdBy: uuid("createdBy").references(() => users.id, {
|
|
onDelete: "set null",
|
|
}),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt"),
|
|
deletedAt: timestamp("deletedAt"),
|
|
deletedBy: uuid("deletedBy").references(() => users.id, {
|
|
onDelete: "set null",
|
|
}),
|
|
boardId: bigint("boardId", { mode: "number" })
|
|
.notNull()
|
|
.references(() => boards.id, { onDelete: "cascade" }),
|
|
importId: bigint("importId", { mode: "number" }).references(() => imports.id),
|
|
}).enableRLS();
|
|
|
|
export const listsRelations = relations(lists, ({ one, many }) => ({
|
|
createdBy: one(users, {
|
|
fields: [lists.createdBy],
|
|
references: [users.id],
|
|
relationName: "listsCreatedByUser",
|
|
}),
|
|
board: one(boards, {
|
|
fields: [lists.boardId],
|
|
references: [boards.id],
|
|
relationName: "listsBoard",
|
|
}),
|
|
cards: many(cards),
|
|
deletedBy: one(users, {
|
|
fields: [lists.deletedBy],
|
|
references: [users.id],
|
|
relationName: "listsDeletedByUser",
|
|
}),
|
|
import: one(imports, {
|
|
fields: [lists.importId],
|
|
references: [imports.id],
|
|
relationName: "listsImport",
|
|
}),
|
|
}));
|