Fix entries insertion (special numbers not saved)

This commit is contained in:
Zoe Roux 2025-01-28 12:33:53 +01:00
parent b0637aeb6a
commit e9c7cfe832
No known key found for this signature in database
3 changed files with 15 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { type SQL, eq, sql } from "drizzle-orm";
import { type Column, type SQL, eq, sql } from "drizzle-orm";
import { db } from "~/db";
import {
entries,
@ -11,6 +11,8 @@ import type { SeedEntry } from "~/models/entry";
import { processOptImage } from "../images";
import { guessNextRefresh } from "../refresh";
type EntryI = typeof entries.$inferInsert;
const generateSlug = (showSlug: string, entry: SeedEntry): string => {
switch (entry.kind) {
case "episode":
@ -27,14 +29,20 @@ export const insertEntries = async (
items: SeedEntry[],
) => {
const retEntries = await db.transaction(async (tx) => {
const vals = items.map((seed) => {
const vals: EntryI[] = items.map((seed) => {
const { translations, videos, ...entry } = seed;
return {
...entry,
showPk: show.pk,
slug: generateSlug(show.slug, seed),
thumbnails: processOptImage(seed.thumbnail),
thumbnail: processOptImage(seed.thumbnail),
nextRefresh: guessNextRefresh(entry.airDate ?? new Date()),
episodeNumber:
entry.kind === "episode"
? entry.episodeNumber
: entry.kind === "special"
? entry.number
: undefined,
};
});
const ret = await tx
@ -111,10 +119,10 @@ export const insertEntries = async (
}));
};
export function computeVideoSlug(showSlug: SQL, needsRendering: SQL) {
export function computeVideoSlug(showSlug: SQL | Column, needsRendering: SQL) {
return sql<string>`
concat(
${showSlug}::text,
${showSlug},
case when ${videos.part} is not null then ('-p' || ${videos.part}) else '' end,
case when ${videos.version} <> 1 then ('-v' || ${videos.version}) else '' end,
case when ${needsRendering} then concat('-', ${videos.rendering}) else '' end

View File

@ -63,7 +63,7 @@ export const entries = schema.table(
extraKind: text(),
airDate: date(),
runtime: integer(),
thumbnails: image(),
thumbnail: image(),
externalId: entry_extid(),

View File

@ -34,7 +34,7 @@ export const videos = schema.table(
);
export const entryVideoJoin = schema.table(
"entry_video_jointure",
"entry_video_join",
{
entry: integer()
.notNull()