diff --git a/api/drizzle.config.ts b/api/drizzle.config.ts index a7947501..50f19f18 100644 --- a/api/drizzle.config.ts +++ b/api/drizzle.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from "drizzle-kit"; export default defineConfig({ out: "./drizzle", - schema: "./src/db/schema.ts", + schema: "./src/db/schema", dialect: "postgresql", dbCredentials: { url: process.env.DATABASE_URL!, diff --git a/api/src/db/schema.ts b/api/src/db/schema/entries.ts similarity index 93% rename from api/src/db/schema.ts rename to api/src/db/schema/entries.ts index 8515f39a..b57d59a9 100644 --- a/api/src/db/schema.ts +++ b/api/src/db/schema/entries.ts @@ -4,15 +4,13 @@ import { date, integer, jsonb, - pgSchema, primaryKey, text, timestamp, uuid, varchar, } from "drizzle-orm/pg-core"; - -const schema = pgSchema("kyoo"); +import { language, schema } from "./utils"; export const entryType = schema.enum("entry_type", [ "unknown", @@ -51,7 +49,7 @@ export const entriesTranslation = schema.table( pk: integer() .notNull() .references(() => entries.pk, { onDelete: "cascade" }), - language: varchar({ length: 255 }).notNull(), + language: language().notNull(), name: text(), description: text(), }, diff --git a/api/src/db/schema/shows.ts b/api/src/db/schema/shows.ts new file mode 100644 index 00000000..895d2369 --- /dev/null +++ b/api/src/db/schema/shows.ts @@ -0,0 +1,89 @@ +import { sql } from "drizzle-orm"; +import { + check, + date, + integer, + jsonb, + primaryKey, + smallint, + text, + timestamp, + uuid, + varchar, +} from "drizzle-orm/pg-core"; +import { language, schema } from "./utils"; + +export const showKind = schema.enum("show_kind", ["serie", "movie"]); +export const showStatus = schema.enum("show_status", ["unknown", "finished", "airing", "planned"]); +export const genres = schema.enum("genres", [ + "action", + "adventure", + "animation", + "comedy", + "crime", + "documentary", + "drama", + "family", + "fantasy", + "history", + "horror", + "music", + "mystery", + "romance", + "science-fiction", + "thriller", + "war", + "western", + "kids", + "reality", + "politics", + "soap", + "talk", +]); + +export const shows = schema.table( + "shows", + { + pk: integer().primaryKey().generatedAlwaysAsIdentity(), + id: uuid().notNull().unique().defaultRandom(), + slug: varchar({ length: 255 }).notNull().unique(), + kind: showKind().notNull(), + genres: genres().array().notNull(), + rating: smallint(), + status: showStatus().notNull(), + startAir: date(), + endAir: date(), + originalLanguage: language(), + + externalId: jsonb().notNull().default({}), + + createdAt: timestamp({ withTimezone: true }), + nextRefresh: timestamp({ withTimezone: true }), + }, + (t) => ({ + ratingValid: check("ratingValid", sql`0 <= ${t.rating} && ${t.rating} <= 100`), + }), +); + +export const showTranslations = schema.table( + "show_translations", + { + pk: integer() + .notNull() + .references(() => shows.pk, { onDelete: "cascade" }), + language: language().notNull(), + name: text().notNull(), + description: text(), + tagline: text(), + aliases: text().array().notNull(), + tags: text().array().notNull(), + trailerUrl: text(), + poster: jsonb(), + thumbnail: jsonb(), + banner: jsonb(), + logo: jsonb(), + }, + (t) => ({ + pk: primaryKey({ columns: [t.pk, t.language] }), + }), +); diff --git a/api/src/db/schema/utils.ts b/api/src/db/schema/utils.ts new file mode 100644 index 00000000..c6151cf4 --- /dev/null +++ b/api/src/db/schema/utils.ts @@ -0,0 +1,5 @@ +import { pgSchema, varchar } from "drizzle-orm/pg-core"; + +export const schema = pgSchema("kyoo"); + +export const language = () => varchar({ length: 255 });