Cleanup external id types in db

This commit is contained in:
Zoe Roux 2024-11-09 16:19:38 +01:00
parent 84ce544f4d
commit ffa42de4f3
No known key found for this signature in database
3 changed files with 39 additions and 16 deletions

View File

@ -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" }),

View File

@ -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",
{

View File

@ -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<T> = {[KeyType in keyof T]: T[KeyType]} & {};