mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Define show schema and split schema
This commit is contained in:
parent
da3a5181df
commit
c40f086244
@ -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!,
|
||||
|
@ -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(),
|
||||
},
|
89
api/src/db/schema/shows.ts
Normal file
89
api/src/db/schema/shows.ts
Normal 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] }),
|
||||
}),
|
||||
);
|
5
api/src/db/schema/utils.ts
Normal file
5
api/src/db/schema/utils.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { pgSchema, varchar } from "drizzle-orm/pg-core";
|
||||
|
||||
export const schema = pgSchema("kyoo");
|
||||
|
||||
export const language = () => varchar({ length: 255 });
|
Loading…
x
Reference in New Issue
Block a user