Fix artwork upload pipeline
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
ALTER TABLE "artwork_assets"
|
||||
ADD COLUMN "user_id" UUID;
|
||||
|
||||
UPDATE "artwork_assets" AS "aa"
|
||||
SET "user_id" = "t"."user_id"
|
||||
FROM "tracks" AS "t"
|
||||
WHERE "t"."artwork_asset_id" = "aa"."id"
|
||||
AND "aa"."user_id" IS NULL;
|
||||
|
||||
ALTER TABLE "artwork_assets"
|
||||
ADD CONSTRAINT "artwork_assets_user_id_fkey"
|
||||
FOREIGN KEY ("user_id") REFERENCES "users"("id")
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE;
|
||||
|
||||
DROP INDEX IF EXISTS "tracks_artwork_asset_id_key";
|
||||
DROP INDEX IF EXISTS "artwork_assets_sha256_key";
|
||||
|
||||
CREATE INDEX "artwork_assets_user_id_idx"
|
||||
ON "artwork_assets"("user_id");
|
||||
|
||||
CREATE UNIQUE INDEX "artwork_assets_user_id_sha256_key"
|
||||
ON "artwork_assets"("user_id", "sha256");
|
||||
@@ -17,6 +17,7 @@ model User {
|
||||
devices Device[]
|
||||
tracks Track[]
|
||||
audioAssets AudioAsset[]
|
||||
artworkAssets ArtworkAsset[]
|
||||
uploadSessions UploadSession[]
|
||||
libraryEvents LibraryEvent[]
|
||||
|
||||
@@ -46,7 +47,7 @@ model Track {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
userId String @db.Uuid @map("user_id")
|
||||
primaryAudioAssetId String? @unique @db.Uuid @map("primary_audio_asset_id")
|
||||
artworkAssetId String? @unique @db.Uuid @map("artwork_asset_id")
|
||||
artworkAssetId String? @db.Uuid @map("artwork_asset_id")
|
||||
title String
|
||||
artist String
|
||||
album String?
|
||||
@@ -96,16 +97,20 @@ model AudioAsset {
|
||||
}
|
||||
|
||||
model ArtworkAsset {
|
||||
userId String? @db.Uuid @map("user_id")
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
sha256 String @unique
|
||||
sha256 String
|
||||
storageKey String @unique @map("storage_key")
|
||||
mimeType String @map("mime_type")
|
||||
width Int?
|
||||
height Int?
|
||||
fileSizeBytes BigInt @map("file_size_bytes")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
track Track? @relation("TrackArtwork")
|
||||
tracks Track[] @relation("TrackArtwork")
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
||||
|
||||
@@unique([userId, sha256])
|
||||
@@index([userId])
|
||||
@@map("artwork_assets")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user