Add seasons in db

This commit is contained in:
Zoe Roux 2024-11-09 16:21:35 +01:00
parent ffa42de4f3
commit 34e145ab23
No known key found for this signature in database
5 changed files with 901 additions and 0 deletions

View File

@ -0,0 +1,40 @@
CREATE TABLE IF NOT EXISTS "kyoo"."season_translation" (
"pk" integer NOT NULL,
"language" varchar(255) NOT NULL,
"name" text,
"description" text,
"poster" jsonb,
"thumbnail" jsonb,
"logo" jsonb,
"banner" jsonb,
CONSTRAINT "season_translation_pk_language_pk" PRIMARY KEY("pk","language")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "kyoo"."seasons" (
"pk" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "kyoo"."seasons_pk_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
"slug" varchar(255) NOT NULL,
"show_pk" integer,
"season_number" integer NOT NULL,
"start_air" date,
"end_air" date,
"external_id" jsonb DEFAULT '{}'::jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now(),
"next_refresh" timestamp with time zone,
CONSTRAINT "seasons_id_unique" UNIQUE("id"),
CONSTRAINT "seasons_slug_unique" UNIQUE("slug"),
CONSTRAINT "seasons_showPk_seasonNumber_unique" UNIQUE("show_pk","season_number")
);
--> statement-breakpoint
ALTER TABLE "kyoo"."entries" ALTER COLUMN "order" DROP NOT NULL;--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "kyoo"."season_translation" ADD CONSTRAINT "season_translation_pk_seasons_pk_fk" FOREIGN KEY ("pk") REFERENCES "kyoo"."seasons"("pk") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "kyoo"."seasons" ADD CONSTRAINT "seasons_show_pk_shows_pk_fk" FOREIGN KEY ("show_pk") REFERENCES "kyoo"."shows"("pk") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

View File

@ -0,0 +1,788 @@
{
"id": "d0f6c500-aa2b-4592-aa31-db646817f708",
"prevId": "32090852-33a7-430a-9df1-97608c063124",
"version": "7",
"dialect": "postgresql",
"tables": {
"kyoo.entries": {
"name": "entries",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "entries_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"show_pk": {
"name": "show_pk",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"order": {
"name": "order",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"season_number": {
"name": "season_number",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"episode_number": {
"name": "episode_number",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"type": {
"name": "type",
"type": "entry_type",
"typeSchema": "kyoo",
"primaryKey": false,
"notNull": true
},
"air_date": {
"name": "air_date",
"type": "date",
"primaryKey": false,
"notNull": false
},
"runtime": {
"name": "runtime",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"thumbnails": {
"name": "thumbnails",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"external_id": {
"name": "external_id",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"next_refresh": {
"name": "next_refresh",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"entries_show_pk_shows_pk_fk": {
"name": "entries_show_pk_shows_pk_fk",
"tableFrom": "entries",
"tableTo": "shows",
"schemaTo": "kyoo",
"columnsFrom": ["show_pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"entries_id_unique": {
"name": "entries_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"entries_slug_unique": {
"name": "entries_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
},
"entries_showPk_seasonNumber_episodeNumber_unique": {
"name": "entries_showPk_seasonNumber_episodeNumber_unique",
"nullsNotDistinct": false,
"columns": ["show_pk", "season_number", "episode_number"]
}
},
"policies": {},
"checkConstraints": {
"order_positive": {
"name": "order_positive",
"value": "\"entries\".\"order\" >= 0"
}
},
"isRLSEnabled": false
},
"kyoo.entries_translation": {
"name": "entries_translation",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"language": {
"name": "language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"entries_translation_pk_entries_pk_fk": {
"name": "entries_translation_pk_entries_pk_fk",
"tableFrom": "entries_translation",
"tableTo": "entries",
"schemaTo": "kyoo",
"columnsFrom": ["pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"entries_translation_pk_language_pk": {
"name": "entries_translation_pk_language_pk",
"columns": ["pk", "language"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.season_translation": {
"name": "season_translation",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"language": {
"name": "language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"poster": {
"name": "poster",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"thumbnail": {
"name": "thumbnail",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"logo": {
"name": "logo",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"banner": {
"name": "banner",
"type": "jsonb",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"season_translation_pk_seasons_pk_fk": {
"name": "season_translation_pk_seasons_pk_fk",
"tableFrom": "season_translation",
"tableTo": "seasons",
"schemaTo": "kyoo",
"columnsFrom": ["pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"season_translation_pk_language_pk": {
"name": "season_translation_pk_language_pk",
"columns": ["pk", "language"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.seasons": {
"name": "seasons",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "seasons_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"show_pk": {
"name": "show_pk",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"season_number": {
"name": "season_number",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"start_air": {
"name": "start_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"end_air": {
"name": "end_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"external_id": {
"name": "external_id",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"next_refresh": {
"name": "next_refresh",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"seasons_show_pk_shows_pk_fk": {
"name": "seasons_show_pk_shows_pk_fk",
"tableFrom": "seasons",
"tableTo": "shows",
"schemaTo": "kyoo",
"columnsFrom": ["show_pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"seasons_id_unique": {
"name": "seasons_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"seasons_slug_unique": {
"name": "seasons_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
},
"seasons_showPk_seasonNumber_unique": {
"name": "seasons_showPk_seasonNumber_unique",
"nullsNotDistinct": false,
"columns": ["show_pk", "season_number"]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.show_translations": {
"name": "show_translations",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"language": {
"name": "language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"tagline": {
"name": "tagline",
"type": "text",
"primaryKey": false,
"notNull": false
},
"aliases": {
"name": "aliases",
"type": "text[]",
"primaryKey": false,
"notNull": true
},
"tags": {
"name": "tags",
"type": "text[]",
"primaryKey": false,
"notNull": true
},
"trailer_url": {
"name": "trailer_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"poster": {
"name": "poster",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"thumbnail": {
"name": "thumbnail",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"banner": {
"name": "banner",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"logo": {
"name": "logo",
"type": "jsonb",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"show_translations_pk_shows_pk_fk": {
"name": "show_translations_pk_shows_pk_fk",
"tableFrom": "show_translations",
"tableTo": "shows",
"schemaTo": "kyoo",
"columnsFrom": ["pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"show_translations_pk_language_pk": {
"name": "show_translations_pk_language_pk",
"columns": ["pk", "language"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.shows": {
"name": "shows",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "shows_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"kind": {
"name": "kind",
"type": "show_kind",
"typeSchema": "kyoo",
"primaryKey": false,
"notNull": true
},
"genres": {
"name": "genres",
"type": "genres[]",
"primaryKey": false,
"notNull": true
},
"rating": {
"name": "rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"runtime": {
"name": "runtime",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "show_status",
"typeSchema": "kyoo",
"primaryKey": false,
"notNull": true
},
"start_air": {
"name": "start_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"end_air": {
"name": "end_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"original_language": {
"name": "original_language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"external_id": {
"name": "external_id",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"next_refresh": {
"name": "next_refresh",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"shows_id_unique": {
"name": "shows_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"shows_slug_unique": {
"name": "shows_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
}
},
"policies": {},
"checkConstraints": {
"rating_valid": {
"name": "rating_valid",
"value": "\"shows\".\"rating\" between 0 and 100"
},
"runtime_valid": {
"name": "runtime_valid",
"value": "\"shows\".\"runtime\" >= 0"
}
},
"isRLSEnabled": false
},
"kyoo.videos": {
"name": "videos",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "videos_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"path": {
"name": "path",
"type": "text",
"primaryKey": false,
"notNull": true
},
"rendering": {
"name": "rendering",
"type": "text",
"primaryKey": false,
"notNull": true
},
"part": {
"name": "part",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"version": {
"name": "version",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 1
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"videos_id_unique": {
"name": "videos_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"videos_slug_unique": {
"name": "videos_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
},
"videos_path_unique": {
"name": "videos_path_unique",
"nullsNotDistinct": false,
"columns": ["path"]
}
},
"policies": {},
"checkConstraints": {
"part_pos": {
"name": "part_pos",
"value": "\"videos\".\"part\" >= 0"
},
"version_pos": {
"name": "version_pos",
"value": "\"videos\".\"version\" >= 0"
}
},
"isRLSEnabled": false
}
},
"enums": {
"kyoo.entry_type": {
"name": "entry_type",
"schema": "kyoo",
"values": ["unknown", "episode", "movie", "special", "extra"]
},
"kyoo.genres": {
"name": "genres",
"schema": "kyoo",
"values": [
"action",
"adventure",
"animation",
"comedy",
"crime",
"documentary",
"drama",
"family",
"fantasy",
"history",
"horror",
"music",
"mystery",
"romance",
"science-fiction",
"thriller",
"war",
"western",
"kids",
"reality",
"politics",
"soap",
"talk"
]
},
"kyoo.show_kind": {
"name": "show_kind",
"schema": "kyoo",
"values": ["serie", "movie"]
},
"kyoo.show_status": {
"name": "show_status",
"schema": "kyoo",
"values": ["unknown", "finished", "airing", "planned"]
}
},
"schemas": {
"kyoo": "kyoo"
},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@ -15,6 +15,13 @@
"when": 1731149082556,
"tag": "0001_video",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1731165599920,
"tag": "0002_seasons",
"breakpoints": true
}
]
}

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: {

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] })],
);