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", "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( export const entries = schema.table(
"entries", "entries",
{ {
@ -37,7 +59,7 @@ export const entries = schema.table(
runtime: integer(), runtime: integer(),
thumbnails: image(), thumbnails: image(),
externalId: jsonb().notNull().default({}), externalId: entryid(),
createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(), createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(),
nextRefresh: timestamp({ withTimezone: true, mode: "string" }), nextRefresh: timestamp({ withTimezone: true, mode: "string" }),

View File

@ -3,6 +3,7 @@ import {
check, check,
date, date,
integer, integer,
jsonb,
primaryKey, primaryKey,
smallint, smallint,
text, text,
@ -10,7 +11,7 @@ import {
uuid, uuid,
varchar, varchar,
} from "drizzle-orm/pg-core"; } 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 showKind = schema.enum("show_kind", ["serie", "movie"]);
export const showStatus = schema.enum("show_status", [ export const showStatus = schema.enum("show_status", [
@ -45,6 +46,20 @@ export const genres = schema.enum("genres", [
"talk", "talk",
]); ]);
export const externalid = () =>
jsonb()
.$type<
Record<
string,
{
dataId: string;
link: string | null;
}
>
>()
.notNull()
.default({});
export const shows = schema.table( export const shows = schema.table(
"shows", "shows",
{ {

View File

@ -23,20 +23,6 @@ export const language = () => varchar({ length: 255 });
export const image = () => export const image = () =>
jsonb().$type<{ id: string; source: string; blurhash: string }>(); 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 // https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts#L58
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {}; type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};