Define show schema and split schema

This commit is contained in:
Zoe Roux 2024-11-01 16:58:46 +01:00
parent da3a5181df
commit c40f086244
No known key found for this signature in database
4 changed files with 97 additions and 5 deletions

View File

@ -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!,

View File

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

View File

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

View File

@ -0,0 +1,5 @@
import { pgSchema, varchar } from "drizzle-orm/pg-core";
export const schema = pgSchema("kyoo");
export const language = () => varchar({ length: 255 });