chore(prisma): add migration for cleanup job refactor and revert test-global-setup.ts

This commit is contained in:
yiling
2026-05-25 10:04:32 +08:00
parent 2e09ce6ab5
commit 4949b92be8
2 changed files with 22 additions and 3 deletions
@@ -0,0 +1,20 @@
/*
Warnings:
- The values [purging] on the enum `AssetStatus` will be removed. If these variants are still used in the database, this will fail.
*/
-- CreateEnum
CREATE TYPE "StorageKeyStatus" AS ENUM ('active', 'purging');
-- AlterEnum
BEGIN;
CREATE TYPE "AssetStatus_new" AS ENUM ('uploading', 'uploaded', 'processing', 'processed', 'trashed', 'pending_purge');
ALTER TABLE "assets" ALTER COLUMN "status" TYPE "AssetStatus_new" USING ("status"::text::"AssetStatus_new");
ALTER TYPE "AssetStatus" RENAME TO "AssetStatus_old";
ALTER TYPE "AssetStatus_new" RENAME TO "AssetStatus";
DROP TYPE "public"."AssetStatus_old";
COMMIT;
-- AlterTable
ALTER TABLE "storage_keys" ADD COLUMN "status" "StorageKeyStatus" NOT NULL DEFAULT 'active';
+2 -3
View File
@@ -1071,9 +1071,8 @@ export class AssetService {
// using FOR UPDATE SKIP LOCKED to ensure multiple servers don't pick up the same keys.
const lockedKeys = await this.prismaClient.$queryRaw<{ id: string; key: string }[]>`
WITH to_purge AS (
SELECT sk.id FROM storage_keys sk
LEFT JOIN assets a ON a.storage_key_id = sk.id
WHERE a.id IS NULL
SELECT id FROM storage_keys sk
WHERE NOT EXISTS (SELECT 1 FROM assets a WHERE a.storage_key_id = sk.id)
AND sk.created_at < NOW() - INTERVAL '24 hours'
AND (sk.status = 'active' OR (sk.status = 'purging' AND sk.updated_at < NOW() - INTERVAL '1 hour'))
LIMIT 100