diff --git a/src/server/prisma/migrations/20221015025649_many_album_artists/migration.sql b/src/server/prisma/migrations/20221015025649_many_album_artists/migration.sql new file mode 100644 index 000000000..acdf6e82d --- /dev/null +++ b/src/server/prisma/migrations/20221015025649_many_album_artists/migration.sql @@ -0,0 +1,35 @@ +/* + Warnings: + + - You are about to drop the column `albumArtistId` on the `Album` table. All the data in the column will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "Album" DROP CONSTRAINT "Album_albumArtistId_fkey"; + +-- AlterTable +ALTER TABLE "Album" DROP COLUMN "albumArtistId"; + +-- AlterTable +ALTER TABLE "Song" ADD COLUMN "albumArtistId" UUID; + +-- CreateTable +CREATE TABLE "_AlbumToAlbumArtist" ( + "A" UUID NOT NULL, + "B" UUID NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "_AlbumToAlbumArtist_AB_unique" ON "_AlbumToAlbumArtist"("A", "B"); + +-- CreateIndex +CREATE INDEX "_AlbumToAlbumArtist_B_index" ON "_AlbumToAlbumArtist"("B"); + +-- AddForeignKey +ALTER TABLE "Song" ADD CONSTRAINT "Song_albumArtistId_fkey" FOREIGN KEY ("albumArtistId") REFERENCES "AlbumArtist"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_AlbumToAlbumArtist" ADD CONSTRAINT "_AlbumToAlbumArtist_A_fkey" FOREIGN KEY ("A") REFERENCES "Album"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_AlbumToAlbumArtist" ADD CONSTRAINT "_AlbumToAlbumArtist_B_fkey" FOREIGN KEY ("B") REFERENCES "AlbumArtist"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/src/server/prisma/schema.prisma b/src/server/prisma/schema.prisma index 140d3ab53..33e44bc6c 100644 --- a/src/server/prisma/schema.prisma +++ b/src/server/prisma/schema.prisma @@ -320,6 +320,7 @@ model AlbumArtist { ratings AlbumArtistRating[] images Image[] favorites Favorite[] + songs Song[] server Server @relation(fields: [serverId], references: [id], onDelete: Cascade) serverId String @db.Uuid @@ -342,15 +343,13 @@ model Album { songs Song[] genres Genre[] artists Artist[] + albumArtists AlbumArtist[] externals External[] serverFolders ServerFolder[] ratings AlbumRating[] images Image[] favorites Favorite[] - albumArtist AlbumArtist? @relation(fields: [albumArtistId], references: [id]) - albumArtistId String? @db.Uuid - server Server @relation(fields: [serverId], references: [id], onDelete: Cascade) serverId String @db.Uuid @@ -413,6 +412,9 @@ model Song { images Image[] favorites Favorite[] + albumArtist AlbumArtist? @relation(fields: [albumArtistId], references: [id]) + albumArtistId String? @db.Uuid + album Album? @relation(fields: [albumId], references: [id]) albumId String? @db.Uuid