diff --git a/api/src/db/schema/entries.ts b/api/src/db/schema/entries.ts index 4393e99c..72d1f3f5 100644 --- a/api/src/db/schema/entries.ts +++ b/api/src/db/schema/entries.ts @@ -22,6 +22,28 @@ export const entryType = schema.enum("entry_type", [ "extra", ]); +export const entryid = () => + jsonb() + .$type< + Record< + string, + | { + // used for movies + dataId: string; + link: string | null; + } + | { + // used for episodes, specials & extra + serieId: string; + season: number | null; + episode: number; + link: string | null; + } + > + >() + .notNull() + .default({}); + export const entries = schema.table( "entries", { @@ -37,7 +59,7 @@ export const entries = schema.table( runtime: integer(), thumbnails: image(), - externalId: jsonb().notNull().default({}), + externalId: entryid(), createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(), nextRefresh: timestamp({ withTimezone: true, mode: "string" }), diff --git a/api/src/db/schema/shows.ts b/api/src/db/schema/shows.ts index c64fd3b6..d5902217 100644 --- a/api/src/db/schema/shows.ts +++ b/api/src/db/schema/shows.ts @@ -3,6 +3,7 @@ import { check, date, integer, + jsonb, primaryKey, smallint, text, @@ -10,7 +11,7 @@ import { uuid, varchar, } from "drizzle-orm/pg-core"; -import { externalid, image, language, schema } from "./utils"; +import { image, language, schema } from "./utils"; export const showKind = schema.enum("show_kind", ["serie", "movie"]); export const showStatus = schema.enum("show_status", [ @@ -45,6 +46,20 @@ export const genres = schema.enum("genres", [ "talk", ]); +export const externalid = () => + jsonb() + .$type< + Record< + string, + { + dataId: string; + link: string | null; + } + > + >() + .notNull() + .default({}); + export const shows = schema.table( "shows", { diff --git a/api/src/db/schema/utils.ts b/api/src/db/schema/utils.ts index f314ccd3..f2de152c 100644 --- a/api/src/db/schema/utils.ts +++ b/api/src/db/schema/utils.ts @@ -23,20 +23,6 @@ export const language = () => varchar({ length: 255 }); export const image = () => jsonb().$type<{ id: string; source: string; blurhash: string }>(); -export const externalid = () => - jsonb() - .$type< - Record< - string, - { - dataId: string; - link: string | null; - } - > - >() - .notNull() - .default({}); - // https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts#L58 type Simplify = {[KeyType in keyof T]: T[KeyType]} & {};