Wire the app, worker, and cleanup entry points onto Prisma Client

Task 4 rewrote src/db.js and src/jobs/jobRepository.js to use Prisma
instead of the hand-rolled mariadb pool. This updates every remaining
call site (app.js, server.js, worker.js, cleanup.js) and the 5 test
files that still referenced getPool/closePool/pool.query, so the app
and full test suite compile and run against Prisma Client.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 01:32:54 +02:00
co-authored by Claude Sonnet 5
parent 3a04da3180
commit 4c9fe8f616
9 changed files with 93 additions and 93 deletions
+18 -18
View File
@@ -3,30 +3,30 @@ import fs from 'node:fs/promises';
import path from 'node:path';
import os from 'node:os';
import sharp from 'sharp';
import { getPool, closePool } from '../src/db.js';
import { getPrismaClient, closePrismaClient } from '../src/db.js';
import { loadConfig } from '../src/config.js';
import { ensureStorageDirs, uploadPath, outputPath } from '../src/storage.js';
import { createJob, getJobByUuid, getJobErrorLog } from '../src/jobs/jobRepository.js';
import { registerImageConverters } from '../src/converters/image.js';
import { processPendingJobs } from '../src/worker.js';
let pool;
let prisma;
let config;
beforeAll(async () => {
registerImageConverters();
config = { ...loadConfig(), storageDir: await fs.mkdtemp(path.join(os.tmpdir(), 'converter-worker-')) };
await ensureStorageDirs(config);
pool = getPool(config);
prisma = getPrismaClient(config);
});
afterAll(async () => {
await closePool();
await closePrismaClient();
await fs.rm(config.storageDir, { recursive: true, force: true });
});
beforeEach(async () => {
await pool.query('DELETE FROM conversion_jobs');
await prisma.conversionJob.deleteMany();
});
async function createPendingImageJob(uuid, sourceFormat, targetFormat) {
@@ -35,7 +35,7 @@ async function createPendingImageJob(uuid, sourceFormat, targetFormat) {
await fs.copyFile(fixturePath, inputFilePath);
const { size: inputSizeBytes } = await fs.stat(inputFilePath);
await createJob(pool, {
await createJob(prisma, {
uuid,
family: 'image',
sourceFormat,
@@ -53,10 +53,10 @@ describe('processPendingJobs', () => {
const uuid = '99999999-9999-4999-8999-999999999999';
await createPendingImageJob(uuid, 'png', 'webp');
const processedCount = await processPendingJobs(pool, config);
const processedCount = await processPendingJobs(prisma, config);
expect(processedCount).toBe(1);
const job = await getJobByUuid(pool, uuid);
const job = await getJobByUuid(prisma, uuid);
expect(job.status).toBe('done');
expect(job.outputPath).toBe(`${uuid}.webp`);
expect(job.outputMimeType).toBe('image/webp');
@@ -86,7 +86,7 @@ describe('processPendingJobs', () => {
await fs.writeFile(uploadPath(config, uuid, 'png'), noisyBuffer);
}
await createJob(pool, {
await createJob(prisma, {
uuid: lowUuid,
family: 'image',
sourceFormat: 'png',
@@ -98,7 +98,7 @@ describe('processPendingJobs', () => {
expiresAt: new Date(Date.now() + 3600 * 1000),
quality: 5,
});
await createJob(pool, {
await createJob(prisma, {
uuid: defaultUuid,
family: 'image',
sourceFormat: 'png',
@@ -110,10 +110,10 @@ describe('processPendingJobs', () => {
expiresAt: new Date(Date.now() + 3600 * 1000),
});
await processPendingJobs(pool, { ...config, workerConcurrency: 2 });
await processPendingJobs(prisma, { ...config, workerConcurrency: 2 });
const lowJob = await getJobByUuid(pool, lowUuid);
const defaultJob = await getJobByUuid(pool, defaultUuid);
const lowJob = await getJobByUuid(prisma, lowUuid);
const defaultJob = await getJobByUuid(prisma, defaultUuid);
expect(lowJob.status).toBe('done');
expect(defaultJob.status).toBe('done');
expect(lowJob.outputSizeBytes).toBeLessThan(defaultJob.outputSizeBytes);
@@ -121,7 +121,7 @@ describe('processPendingJobs', () => {
it('marks a job failed with a safe message and a detailed log when the converter throws', async () => {
const uuid = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
await createJob(pool, {
await createJob(prisma, {
uuid,
family: 'image',
sourceFormat: 'png',
@@ -134,13 +134,13 @@ describe('processPendingJobs', () => {
});
// Note: input file is intentionally never written, so sharp will throw ENOENT.
await processPendingJobs(pool, config);
await processPendingJobs(prisma, config);
const job = await getJobByUuid(pool, uuid);
const job = await getJobByUuid(prisma, uuid);
expect(job.status).toBe('failed');
expect(job.errorMessage).toBe('Conversion failed, please try again.');
const errorLog = await getJobErrorLog(pool, job.id);
const errorLog = await getJobErrorLog(prisma, job.id);
expect(errorLog).toMatch(/input file is missing/i);
});
@@ -150,7 +150,7 @@ describe('processPendingJobs', () => {
await createPendingImageJob('dddddddd-dddd-4ddd-8ddd-dddddddddddd', 'png', 'webp');
const limitedConfig = { ...config, workerConcurrency: 2 };
const processedCount = await processPendingJobs(pool, limitedConfig);
const processedCount = await processPendingJobs(prisma, limitedConfig);
expect(processedCount).toBe(2);
});