diff --git a/api/drizzle.config.ts b/api/drizzle.config.ts index 50f19f18..cf35e7c2 100644 --- a/api/drizzle.config.ts +++ b/api/drizzle.config.ts @@ -4,6 +4,7 @@ export default defineConfig({ out: "./drizzle", schema: "./src/db/schema", dialect: "postgresql", + casing: "snake_case", dbCredentials: { url: process.env.DATABASE_URL!, }, diff --git a/api/src/db/schema/entries.ts b/api/src/db/schema/entries.ts index dfb13fd4..d9dcca51 100644 --- a/api/src/db/schema/entries.ts +++ b/api/src/db/schema/entries.ts @@ -7,10 +7,12 @@ import { primaryKey, text, timestamp, + unique, uuid, varchar, } from "drizzle-orm/pg-core"; import { image, language, schema } from "./utils"; +import { shows } from "./shows"; export const entryType = schema.enum("entry_type", [ "unknown", @@ -26,7 +28,7 @@ export const entries = schema.table( pk: integer().primaryKey().generatedAlwaysAsIdentity(), id: uuid().notNull().unique().defaultRandom(), slug: varchar({ length: 255 }).notNull().unique(), - // showId: integer().references(() => show.id), + showId: integer().references(() => shows.id, { onDelete: "cascade" }), order: integer().notNull(), seasonNumber: integer(), episodeNumber: integer(), @@ -40,10 +42,10 @@ export const entries = schema.table( createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(), nextRefresh: timestamp({ withTimezone: true, mode: "string" }), }, - (t) => ({ - // episodeKey: unique().on(t.showId, t.seasonNumber, t.episodeNumber), - orderPositive: check("orderPositive", sql`${t.order} >= 0`), - }), + (t) => [ + unique().on(t.showId, t.seasonNumber, t.episodeNumber), + check("order_positive", sql`${t.order} >= 0`), + ], ); export const entriesTranslation = schema.table( @@ -56,7 +58,5 @@ export const entriesTranslation = schema.table( name: text(), description: text(), }, - (t) => ({ - pk: primaryKey({ columns: [t.pk, t.language] }), - }), + (t) => [primaryKey({ columns: [t.pk, t.language] })], ); diff --git a/api/src/db/schema/shows.ts b/api/src/db/schema/shows.ts index e090903d..c64fd3b6 100644 --- a/api/src/db/schema/shows.ts +++ b/api/src/db/schema/shows.ts @@ -67,13 +67,10 @@ export const shows = schema.table( .defaultNow(), nextRefresh: timestamp({ withTimezone: true, mode: "string" }).notNull(), }, - (t) => ({ - ratingValid: check( - "ratingValid", - sql`${t.rating} between 0 and 100`, - ), - runtimeValid: check("runtimeValid", sql`0 <= ${t.runtime}`), - }), + (t) => [ + check("rating_valid", sql`${t.rating} between 0 and 100`), + check("runtime_valid", sql`${t.runtime} >= 0`), + ], ); export const showTranslations = schema.table( @@ -94,7 +91,5 @@ export const showTranslations = schema.table( banner: image(), logo: image(), }, - (t) => ({ - pk: primaryKey({ columns: [t.pk, t.language] }), - }), + (t) => [primaryKey({ columns: [t.pk, t.language] })], ); diff --git a/api/src/db/schema/videos.ts b/api/src/db/schema/videos.ts index a4ad244f..86574f81 100644 --- a/api/src/db/schema/videos.ts +++ b/api/src/db/schema/videos.ts @@ -14,9 +14,9 @@ export const videos = schema.table( createdAt: timestamp({ withTimezone: true }).notNull().defaultNow(), }, - (t) => ({ - ratingValid: check("renderingPos", sql`0 <= ${t.rendering}`), - partValid: check("partPos", sql`0 <= ${t.part}`), - versionValid: check("versionPos", sql`0 <= ${t.version}`), - }), + (t) => [ + check("rendering_pos", sql`${t.rendering} >= 0`), + check("part_pos", sql`${t.part} >= 0`), + check("version_pos", sql`${t.version} >= 0`), + ], );