Fix unnest issues

This commit is contained in:
Zoe Roux
2025-11-28 17:11:29 +01:00
parent 8fc279d2ed
commit 464d720ef9
6 changed files with 20 additions and 14 deletions
@@ -73,9 +73,10 @@ export const insertCollection = async (
}),
);
await flushImageQueue(tx, imgQueue, 100);
// we can't unnest values here because show translations contains arrays.
await tx
.insert(showTranslations)
.select(unnestValues(trans, showTranslations))
.values(trans)
.onConflictDoUpdate({
target: [showTranslations.pk, showTranslations.language],
set: conflictUpdateAllExcept(showTranslations, ["pk", "language"]),
+5 -5
View File
@@ -161,22 +161,22 @@ export const insertEntries = async (
.select(
db
.select({
entryPk: sql<number>`vids.entryPk`.as("entry"),
entryPk: sql<number>`vids."entryPk"`.as("entry"),
videoPk: videos.pk,
slug: computeVideoSlug(
sql`vids.entrySlug`,
sql`vids.needRendering`,
sql`vids."entrySlug"`,
sql`vids."needRendering"`,
),
})
.from(
unnest(vids, "vids", {
entryPk: "integer",
entrySlug: "string",
entrySlug: "varchar(255)",
needRendering: "boolean",
videoId: "uuid",
}),
)
.innerJoin(videos, eq(videos.id, sql`vids.videoId`)),
.innerJoin(videos, eq(videos.id, sql`vids."videoId"`)),
)
.onConflictDoNothing()
.returning({
+2 -1
View File
@@ -93,9 +93,10 @@ export const insertShow = async (
}),
);
await flushImageQueue(tx, imgQueue, 200);
// we can't unnest values here because show translations contains arrays.
await tx
.insert(showTranslations)
.select(unnestValues(trans, showTranslations))
.values(trans)
.onConflictDoUpdate({
target: [showTranslations.pk, showTranslations.language],
set: conflictUpdateAllExcept(showTranslations, ["pk", "language"]),
+2 -2
View File
@@ -61,9 +61,9 @@ export const insertStudios = async (
db
.select({
showPk: sql`${showPk}`.as("showPk"),
studioPk: sql`v.studioPk`.as("studioPk"),
studioPk: sql`v."studioPk"`.as("studioPk"),
})
.from(sql`unnest(${sqlarr(ret.map((x) => x.pk))}) as v("studioPk")`),
.from(sql`unnest(${sqlarr(ret.map((x) => x.pk))}::integer[]) as v("studioPk")`),
)
.onConflictDoNothing();
return ret;