mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add history table
This commit is contained in:
parent
e9db7b6285
commit
781a6a8196
@ -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
|
||||
|
25
api/src/db/schema/history.ts
Normal file
25
api/src/db/schema/history.ts
Normal 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())],
|
||||
);
|
@ -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";
|
||||
|
6
api/src/db/schema/profiles.ts
Normal file
6
api/src/db/schema/profiles.ts
Normal 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(),
|
||||
});
|
10
api/src/models/watchlist.ts
Normal file
10
api/src/models/watchlist.ts
Normal 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;
|
Loading…
x
Reference in New Issue
Block a user