Edit slug constraints on (kind, slug) for shows

This commit is contained in:
Zoe Roux 2026-02-19 13:48:27 +01:00
parent 31af752e2e
commit b7e1c4dc3e
No known key found for this signature in database
7 changed files with 2206 additions and 5 deletions

View File

@ -0,0 +1,3 @@
ALTER TABLE "kyoo"."shows" DROP CONSTRAINT "shows_slug_unique";--> statement-breakpoint
CREATE INDEX "slug" ON "kyoo"."shows" USING btree ("slug");--> statement-breakpoint
ALTER TABLE "kyoo"."shows" ADD CONSTRAINT "kind_slug" UNIQUE("kind","slug");

File diff suppressed because it is too large Load Diff

View File

@ -190,6 +190,13 @@
"when": 1768560733256,
"tag": "0026_precision",
"breakpoints": true
},
{
"idx": 27,
"version": "7",
"when": 1771505332722,
"tag": "0027_show_slug",
"breakpoints": true
}
]
}

View File

@ -184,8 +184,8 @@ export const imagesH = new Elysia({ tags: ["images"] })
.where(
id !== "random"
? isUuid(id)
? eq(shows.id, id)
: eq(shows.slug, id)
? eq(staff.id, id)
: eq(staff.slug, id)
: undefined,
)
.orderBy(sql`random()`)

View File

@ -47,7 +47,7 @@ export const insertCollection = record(
...col,
})
.onConflictDoUpdate({
target: shows.slug,
target: [shows.kind, shows.slug],
set: {
...conflictUpdateAllExcept(shows, [
"pk",

View File

@ -119,7 +119,7 @@ async function insertBaseShow(tx: Transaction, show: Show) {
.insert(shows)
.values(show)
.onConflictDoUpdate({
target: shows.slug,
target: [shows.kind, shows.slug],
set: conflictUpdateAllExcept(shows, ["pk", "id", "slug", "createdAt"]),
// if year is different, this is not an update but a conflict (ex: dune-1984 vs dune-2021)
setWhere: sql`date_part('year', ${shows.startAir}) = date_part('year', excluded."start_air")`,

View File

@ -12,6 +12,7 @@ import {
timestamp,
uuid,
varchar,
unique,
} from "drizzle-orm/pg-core";
import type { Image, Original } from "~/models/utils";
import { entries } from "./entries";
@ -69,7 +70,7 @@ export const shows = schema.table(
{
pk: integer().primaryKey().generatedAlwaysAsIdentity(),
id: uuid().notNull().unique().defaultRandom(),
slug: varchar({ length: 255 }).notNull().unique(),
slug: varchar({ length: 255 }).notNull(),
kind: showKind().notNull(),
genres: genres().array().notNull(),
rating: smallint(),
@ -96,10 +97,13 @@ export const shows = schema.table(
nextRefresh: timestamp({ withTimezone: true, precision: 3 }).notNull(),
},
(t) => [
unique("kind_slug").on(t.kind, t.slug),
check("rating_valid", sql`${t.rating} between 0 and 100`),
check("runtime_valid", sql`${t.runtime} >= 0`),
index("kind").using("hash", t.kind),
index("slug").on(t.slug),
index("rating").on(t.rating),
index("startAir").on(t.startAir),
],