76 lines
2.8 KiB
TypeScript
76 lines
2.8 KiB
TypeScript
import {
|
|
boolean,
|
|
index,
|
|
integer,
|
|
pgTable,
|
|
primaryKey,
|
|
text,
|
|
timestamp,
|
|
uniqueIndex,
|
|
} from "drizzle-orm/pg-core";
|
|
import { recommendationStatusEnum, recommendationStrengthEnum, reactionTypeEnum } from "./enums";
|
|
import { users } from "./auth";
|
|
import { mediaItems } from "./media";
|
|
import { workspaces } from "./workspaces";
|
|
export const recommendations = pgTable(
|
|
"recommendation",
|
|
{
|
|
id: text("id").primaryKey(),
|
|
workspaceId: text("workspace_id")
|
|
.notNull()
|
|
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
mediaItemId: text("media_item_id")
|
|
.notNull()
|
|
.references(() => mediaItems.id, { onDelete: "restrict" }),
|
|
recommendedByUserId: text("recommended_by_user_id")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "restrict" }),
|
|
reason: text("reason").notNull(),
|
|
audienceNote: text("audience_note"),
|
|
strength: recommendationStrengthEnum("strength").notNull().default("NORMAL"),
|
|
containsSpoilers: boolean("contains_spoilers").notNull().default(false),
|
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
},
|
|
(table) => [
|
|
uniqueIndex("recommendation_workspace_media_unique").on(table.workspaceId, table.mediaItemId),
|
|
index("recommendation_workspace_created_idx").on(table.workspaceId, table.createdAt),
|
|
],
|
|
);
|
|
export const recommendationStatuses = pgTable(
|
|
"recommendation_status",
|
|
{
|
|
recommendationId: text("recommendation_id")
|
|
.notNull()
|
|
.references(() => recommendations.id, { onDelete: "cascade" }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
status: recommendationStatusEnum("status").notNull().default("PENDING"),
|
|
rating: integer("rating"),
|
|
review: text("review"),
|
|
startedAt: timestamp("started_at", { withTimezone: true }),
|
|
completedAt: timestamp("completed_at", { withTimezone: true }),
|
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
},
|
|
(table) => [
|
|
primaryKey({ columns: [table.recommendationId, table.userId] }),
|
|
index("recommendation_status_user_idx").on(table.userId),
|
|
],
|
|
);
|
|
export const recommendationReactions = pgTable(
|
|
"recommendation_reaction",
|
|
{
|
|
recommendationId: text("recommendation_id")
|
|
.notNull()
|
|
.references(() => recommendations.id, { onDelete: "cascade" }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
type: reactionTypeEnum("type").notNull(),
|
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
},
|
|
(table) => [primaryKey({ columns: [table.recommendationId, table.userId, table.type] })],
|
|
);
|