mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(api): fix batch user-files delete recursive CTE query
The refactored CTE used = ANY(${validIds}::uuid[]) which Drizzle
serializes as a scalar text parameter with a ::uuid[] cast. Since
the user_files.id column is text (not uuid), PostgreSQL rejects
the text = uuid comparison. Replace with IN (...) via sql.join()
to pass each ID as a plain text parameter matching the column type.
This commit is contained in:
@@ -505,11 +505,15 @@ export async function userFileRoutes(app: FastifyInstance): Promise<void> {
|
||||
};
|
||||
|
||||
// Single recursive CTE to collect all chain members for every valid ID
|
||||
const seedIds = sql.join(
|
||||
validIds.map((id) => sql`${id}`),
|
||||
sql`, `,
|
||||
);
|
||||
const cteResult = await db.execute<DeleteChainRow>(sql`
|
||||
WITH RECURSIVE
|
||||
ancestors(id, parent_id) AS (
|
||||
SELECT id, parent_id FROM user_files
|
||||
WHERE id = ANY(${validIds}::uuid[])
|
||||
WHERE id IN (${seedIds})
|
||||
UNION ALL
|
||||
SELECT uf.id, uf.parent_id FROM user_files uf
|
||||
INNER JOIN ancestors a ON uf.id = a.parent_id
|
||||
|
||||
Reference in New Issue
Block a user