mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-24 08:02:26 -04:00
Type json in drizzle schemas
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
uuid,
|
||||
varchar,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { language, schema } from "./utils";
|
||||
import { image, language, schema } from "./utils";
|
||||
|
||||
export const entryType = schema.enum("entry_type", [
|
||||
"unknown",
|
||||
@@ -33,7 +33,7 @@ export const entries = schema.table(
|
||||
type: entryType().notNull(),
|
||||
airDate: date(),
|
||||
runtime: integer(),
|
||||
thumbnails: jsonb(),
|
||||
thumbnails: image(),
|
||||
|
||||
externalId: jsonb().notNull().default({}),
|
||||
|
||||
|
||||
+20
-12
@@ -11,10 +11,15 @@ import {
|
||||
uuid,
|
||||
varchar,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { language, schema } from "./utils";
|
||||
import { externalid, image, 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 showStatus = schema.enum("show_status", [
|
||||
"unknown",
|
||||
"finished",
|
||||
"airing",
|
||||
"planned",
|
||||
]);
|
||||
export const genres = schema.enum("genres", [
|
||||
"action",
|
||||
"adventure",
|
||||
@@ -51,17 +56,20 @@ export const shows = schema.table(
|
||||
genres: genres().array().notNull(),
|
||||
rating: smallint(),
|
||||
status: showStatus().notNull(),
|
||||
startAir: date(),
|
||||
endAir: date(),
|
||||
startAir: date({ mode: "date" }),
|
||||
endAir: date({ mode: "date" }),
|
||||
originalLanguage: language(),
|
||||
|
||||
externalId: jsonb().notNull().default({}),
|
||||
externalId: externalid(),
|
||||
|
||||
createdAt: timestamp({ withTimezone: true }).defaultNow(),
|
||||
nextRefresh: timestamp({ withTimezone: true }),
|
||||
createdAt: timestamp({ withTimezone: true }).notNull().defaultNow(),
|
||||
nextRefresh: timestamp({ withTimezone: true }).notNull(),
|
||||
},
|
||||
(t) => ({
|
||||
ratingValid: check("ratingValid", sql`0 <= ${t.rating} && ${t.rating} <= 100`),
|
||||
ratingValid: check(
|
||||
"ratingValid",
|
||||
sql`0 <= ${t.rating} && ${t.rating} <= 100`,
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -78,10 +86,10 @@ export const showTranslations = schema.table(
|
||||
aliases: text().array().notNull(),
|
||||
tags: text().array().notNull(),
|
||||
trailerUrl: text(),
|
||||
poster: jsonb(),
|
||||
thumbnail: jsonb(),
|
||||
banner: jsonb(),
|
||||
logo: jsonb(),
|
||||
poster: image(),
|
||||
thumbnail: image(),
|
||||
banner: image(),
|
||||
logo: image(),
|
||||
},
|
||||
(t) => ({
|
||||
pk: primaryKey({ columns: [t.pk, t.language] }),
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
import { pgSchema, varchar } from "drizzle-orm/pg-core";
|
||||
import { jsonb, pgSchema, varchar } from "drizzle-orm/pg-core";
|
||||
|
||||
export const schema = pgSchema("kyoo");
|
||||
|
||||
export const language = () => varchar({ length: 255 });
|
||||
|
||||
export const image = () =>
|
||||
jsonb().$type<{ source: string; blurhash: string }>();
|
||||
|
||||
export const externalid = () =>
|
||||
jsonb()
|
||||
.$type<
|
||||
Record<
|
||||
string,
|
||||
{
|
||||
dataId: string;
|
||||
link: string | null;
|
||||
}
|
||||
>
|
||||
>()
|
||||
.notNull()
|
||||
.default({});
|
||||
|
||||
Reference in New Issue
Block a user