Add seasons in db

This commit is contained in:
Zoe Roux
2024-11-09 16:21:35 +01:00
parent ffa42de4f3
commit 34e145ab23
5 changed files with 901 additions and 0 deletions
+2
View File
@@ -1,5 +1,6 @@
import { drizzle } from "drizzle-orm/node-postgres";
import * as entries from "./schema/entries";
import * as seasons from "./schema/seasons";
import * as shows from "./schema/shows";
import * as videos from "./schema/videos";
@@ -7,6 +8,7 @@ export const db = drizzle({
schema: {
...entries,
...shows,
...seasons,
...videos,
},
connection: {
+64
View File
@@ -0,0 +1,64 @@
import {
date,
integer,
jsonb,
primaryKey,
text,
timestamp,
unique,
uuid,
varchar,
} from "drizzle-orm/pg-core";
import { image, language, schema } from "./utils";
import { shows } from "./shows";
export const entryid = () =>
jsonb()
.$type<
Record<
string,
{
serieId: string;
season: number;
link: string | null;
}
>
>()
.notNull()
.default({});
export const seasons = schema.table(
"seasons",
{
pk: integer().primaryKey().generatedAlwaysAsIdentity(),
id: uuid().notNull().unique().defaultRandom(),
slug: varchar({ length: 255 }).notNull().unique(),
showPk: integer().references(() => shows.pk, { onDelete: "cascade" }),
seasonNumber: integer().notNull(),
startAir: date(),
endAir: date(),
externalId: entryid(),
createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(),
nextRefresh: timestamp({ withTimezone: true, mode: "string" }),
},
(t) => [unique().on(t.showPk, t.seasonNumber)],
);
export const seasonTranslation = schema.table(
"season_translation",
{
pk: integer()
.notNull()
.references(() => seasons.pk, { onDelete: "cascade" }),
language: language().notNull(),
name: text(),
description: text(),
poster: image(),
thumbnail: image(),
logo: image(),
banner: image(),
},
(t) => [primaryKey({ columns: [t.pk, t.language] })],
);