Add history table

This commit is contained in:
Zoe Roux 2025-03-11 14:37:26 +01:00
parent e9db7b6285
commit 781a6a8196
No known key found for this signature in database
5 changed files with 48 additions and 3 deletions

View File

@ -116,13 +116,14 @@ erDiagram
history {
int id PK
guid entry_id FK
guid user_id FK
uint time "in seconds, null of finished"
uint progress "NN, from 0 to 100"
guid profile_id FK
guid video_id FK
jsonb progress "{ percent, time }"
datetime played_date
}
entries ||--|{ history : part_of
users ||--|{ history : has
videos o|--o{ history : has
roles {
guid show_id PK, FK
@ -143,6 +144,7 @@ erDiagram
jsonb external_id
}
staff ||--|{ roles : has
shows ||--|{ roles : has
studios {
guid id PK

View File

@ -0,0 +1,25 @@
import { index, integer, jsonb, timestamp } from "drizzle-orm/pg-core";
import type { Progress } from "~/models/watchlist";
import { entries } from "./entries";
import { profiles } from "./profiles";
import { schema } from "./utils";
import { videos } from "./videos";
export const history = schema.table(
"history",
{
pk: integer().primaryKey().generatedAlwaysAsIdentity(),
profilePk: integer()
.notNull()
.references(() => profiles.pk, { onDelete: "cascade" }),
entryPk: integer()
.notNull()
.references(() => entries.pk, { onDelete: "cascade" }),
videoPk: integer()
.notNull()
.references(() => videos.pk, { onDelete: "set null" }),
progress: jsonb().$type<Progress>(),
playedDate: timestamp({ mode: "string" }).notNull().defaultNow(),
},
(t) => [index("history_play_date").on(t.playedDate.desc())],
);

View File

@ -4,4 +4,6 @@ export * from "./shows";
export * from "./studios";
export * from "./staff";
export * from "./videos";
export * from "./profiles";
export * from "./history";
export * from "./mqueue";

View File

@ -0,0 +1,6 @@
import { integer } from "drizzle-orm/pg-core";
import { schema } from "./utils";
export const profiles = schema.table("profiles", {
pk: integer().primaryKey().generatedAlwaysAsIdentity(),
});

View File

@ -0,0 +1,10 @@
import { t } from "elysia";
export const Progress = t.Object({
percent: t.Integer({ minimum: 0, maximum: 100 }),
time: t.Number({
minimum: 0,
description: "When this episode was stopped (in seconds since the start",
}),
});
export type Progress = typeof Progress.static;