mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-03-20 16:37:50 -04:00
Edit slug constraints on (kind, slug) for shows
This commit is contained in:
parent
31af752e2e
commit
b7e1c4dc3e
3
api/drizzle/0027_show_slug.sql
Normal file
3
api/drizzle/0027_show_slug.sql
Normal 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");
|
||||
2187
api/drizzle/meta/0027_snapshot.json
Normal file
2187
api/drizzle/meta/0027_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -190,6 +190,13 @@
|
||||
"when": 1768560733256,
|
||||
"tag": "0026_precision",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 27,
|
||||
"version": "7",
|
||||
"when": 1771505332722,
|
||||
"tag": "0027_show_slug",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -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()`)
|
||||
|
||||
@ -47,7 +47,7 @@ export const insertCollection = record(
|
||||
...col,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: shows.slug,
|
||||
target: [shows.kind, shows.slug],
|
||||
set: {
|
||||
...conflictUpdateAllExcept(shows, [
|
||||
"pk",
|
||||
|
||||
@ -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")`,
|
||||
|
||||
@ -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),
|
||||
],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user