Add watchlist table

This commit is contained in:
Zoe Roux 2025-03-11 16:34:00 +01:00
parent 31a749b5ed
commit e489d0c445
No known key found for this signature in database
3 changed files with 60 additions and 8 deletions

View File

@ -63,14 +63,14 @@ erDiagram
} }
entries ||--|{ entry_translations : has entries ||--|{ entry_translations : has
video { videos {
guid id PK guid id PK
string path "NN" string path "NN"
uint rendering "dedup for duplicates part1/2" uint rendering "dedup for duplicates part1/2"
uint part uint part
uint version "max version is preferred rendering" uint version "max version is preferred rendering"
} }
video }|--|{ entries : for videos }|--|{ entries : for
seasons { seasons {
guid id PK guid id PK
@ -102,16 +102,16 @@ erDiagram
guid id PK guid id PK
} }
watched_shows { watchlist {
guid show_id PK, FK guid show_id PK, FK
guid user_id PK, FK guid user_id PK, FK
status status "completed|watching|dropped|planned" status status "completed|watching|rewatching|dropped|planned"
uint seen_entry_count "NN" uint seen_entry_count "NN"
guid next_entry FK guid next_entry FK
} }
shows ||--|{ watched_shows : has shows ||--|{ watchlist : has
users ||--|{ watched_shows : has users ||--|{ watchlist : has
watched_shows ||--|o entries : next_entry watchlist ||--|o entries : next_entry
history { history {
int id PK int id PK

View File

@ -20,7 +20,9 @@ export const history = schema.table(
.references(() => videos.pk, { onDelete: "set null" }), .references(() => videos.pk, { onDelete: "set null" }),
percent: integer().notNull().default(0), percent: integer().notNull().default(0),
time: integer(), time: integer(),
playedDate: timestamp({ mode: "string" }).notNull().defaultNow(), playedDate: timestamp({ withTimezone: true, mode: "string" })
.notNull()
.defaultNow(),
}, },
(t) => [ (t) => [
index("history_play_date").on(t.playedDate.desc()), index("history_play_date").on(t.playedDate.desc()),

View File

@ -0,0 +1,50 @@
import { sql } from "drizzle-orm";
import {
check,
integer,
primaryKey,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { entries } from "./entries";
import { profiles } from "./profiles";
import { shows } from "./shows";
import { schema } from "./utils";
export const watchlistStatus = schema.enum("watchlist_status", [
"completed",
"watching",
"rewatching",
"dropped",
"planned",
]);
export const watchlist = schema.table(
"watchlist",
{
profilePk: integer()
.notNull()
.references(() => profiles.pk, { onDelete: "cascade" }),
showPk: integer()
.notNull()
.references(() => shows.pk, { onDelete: "cascade" }),
status: watchlistStatus().notNull(),
seenCount: integer().notNull().default(0),
nextEntry: integer().references(() => entries.pk, { onDelete: "set null" }),
score: integer(),
notes: text(),
createdAt: timestamp({ withTimezone: true, mode: "string" })
.notNull()
.defaultNow(),
updatedAt: timestamp({ withTimezone: true, mode: "string" })
.notNull()
.$onUpdate(() => sql`now()`),
},
(t) => [
primaryKey({ columns: [t.profilePk, t.showPk] }),
check("score_percent", sql`${t.score} between 0 and 100`),
],
);