diff --git a/api/src/db/index.ts b/api/src/db/index.ts index 5be8aa52..c2b0d003 100644 --- a/api/src/db/index.ts +++ b/api/src/db/index.ts @@ -1,16 +1,8 @@ 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"; +import * as schema from "./schema"; export const db = drizzle({ - schema: { - ...entries, - ...shows, - ...seasons, - ...videos, - }, + schema, connection: { user: process.env.POSTGRES_USER ?? "kyoo", password: process.env.POSTGRES_PASSWORD ?? "password", diff --git a/api/src/db/schema/entries.ts b/api/src/db/schema/entries.ts index b1bf583b..1a5e747b 100644 --- a/api/src/db/schema/entries.ts +++ b/api/src/db/schema/entries.ts @@ -23,7 +23,7 @@ export const entryType = schema.enum("entry_type", [ "extra", ]); -export const entryid = () => +export const entry_extid = () => jsonb() .$type< Record< @@ -60,7 +60,7 @@ export const entries = schema.table( runtime: integer(), thumbnails: image(), - externalId: entryid(), + externalId: entry_extid(), createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(), nextRefresh: timestamp({ withTimezone: true, mode: "string" }), @@ -71,8 +71,8 @@ export const entries = schema.table( ], ); -export const entriesTranslation = schema.table( - "entries_translation", +export const entryTranslations = schema.table( + "entry_translations", { pk: integer() .notNull() diff --git a/api/src/db/schema/index.ts b/api/src/db/schema/index.ts new file mode 100644 index 00000000..c817ce8c --- /dev/null +++ b/api/src/db/schema/index.ts @@ -0,0 +1,4 @@ +export * from "./entries"; +export * from "./seasons"; +export * from "./shows"; +export * from "./videos"; diff --git a/api/src/db/schema/seasons.ts b/api/src/db/schema/seasons.ts index da65f3d0..85405c0f 100644 --- a/api/src/db/schema/seasons.ts +++ b/api/src/db/schema/seasons.ts @@ -12,7 +12,7 @@ import { import { image, language, schema } from "./utils"; import { shows } from "./shows"; -export const entryid = () => +export const season_extid = () => jsonb() .$type< Record< @@ -38,7 +38,7 @@ export const seasons = schema.table( startAir: date(), endAir: date(), - externalId: entryid(), + externalId: season_extid(), createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(), nextRefresh: timestamp({ withTimezone: true, mode: "string" }), @@ -47,7 +47,7 @@ export const seasons = schema.table( ); export const seasonTranslation = schema.table( - "season_translation", + "season_translations", { pk: integer() .notNull() diff --git a/api/src/db/schema/videos.ts b/api/src/db/schema/videos.ts index 101287ea..cb82704f 100644 --- a/api/src/db/schema/videos.ts +++ b/api/src/db/schema/videos.ts @@ -15,14 +15,16 @@ export const videos = schema.table( { pk: integer().primaryKey().generatedAlwaysAsIdentity(), id: uuid().notNull().unique().defaultRandom(), - slug: varchar({ length: 255 }).notNull().unique(), + slug: varchar({ length: 255 }).unique(), path: text().notNull().unique(), rendering: text().notNull(), part: integer(), version: integer().notNull().default(1), guess: jsonb().notNull().default({}), - createdAt: timestamp({ withTimezone: true }).notNull().defaultNow(), + createdAt: timestamp({ withTimezone: true, mode: "string" }) + .notNull() + .defaultNow(), }, (t) => [ check("part_pos", sql`${t.part} >= 0`),