From 60a3ef354181393d5358121b0e9a1a4f4fc6e1ee Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 7 Apr 2025 14:50:47 -0600 Subject: [PATCH] Implement album stores field --- .../migration.sql | 10 ++++++++++ prisma/schema.prisma | 12 +++++------- src/pages/api/album/create.ts | 1 + src/pages/api/album/edit.ts | 3 ++- 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 prisma/migrations/20250407204447_remove_sequelize_columns_stores/migration.sql diff --git a/prisma/migrations/20250407204447_remove_sequelize_columns_stores/migration.sql b/prisma/migrations/20250407204447_remove_sequelize_columns_stores/migration.sql new file mode 100644 index 0000000..962f146 --- /dev/null +++ b/prisma/migrations/20250407204447_remove_sequelize_columns_stores/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - You are about to drop the column `createdAt` on the `stores` table. All the data in the column will be lost. + - You are about to drop the column `updatedAt` on the `stores` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE `stores` DROP COLUMN `createdAt`, + DROP COLUMN `updatedAt`; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 18b492e..6c14915 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -369,13 +369,11 @@ model series { } model stores { - id Int @id @default(autoincrement()) - url String? @db.VarChar(255) - provider String? @db.VarChar(255) - createdAt DateTime @db.DateTime(0) - updatedAt DateTime @db.DateTime(0) - albumId Int? - album albums? @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "stores_ibfk_1") + id Int @id @default(autoincrement()) + url String? @db.VarChar(255) + provider String? @db.VarChar(255) + albumId Int? + album albums? @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "stores_ibfk_1") } model studio { diff --git a/src/pages/api/album/create.ts b/src/pages/api/album/create.ts index 0906892..cd73649 100644 --- a/src/pages/api/album/create.ts +++ b/src/pages/api/album/create.ts @@ -53,6 +53,7 @@ export const POST: APIRoute = async ({ request, locals }) => { platforms: { create: body.platforms.map((id) => ({ platform: { connect: { id } } })) }, // albumHistories discs: { createMany: { data: body.discs } }, + stores: { createMany: { data: body.stores } }, relatedAlbums: { create: body.related.map((id) => ({ relatedAlbum: { connect: { id } } })) } }, include: { artists: { include: { artist: { select: { name: true } } } } } diff --git a/src/pages/api/album/edit.ts b/src/pages/api/album/edit.ts index e3d9de2..90efb04 100644 --- a/src/pages/api/album/edit.ts +++ b/src/pages/api/album/edit.ts @@ -60,7 +60,8 @@ export const POST: APIRoute = async ({ request, locals }) => { platforms: { deleteMany: {}, create: platforms?.map((id) => ({ platform: { connect: { id } } })) }, discs: { deleteMany: {}, createMany: { data: body.discs ?? [] } }, relatedAlbums: { deleteMany: {}, create: related?.map((id) => ({ relatedAlbum: { connect: { id } } })) }, - downloads: { deleteMany: {} } + downloads: { deleteMany: {} }, + stores: stores ? { deleteMany: {}, createMany: { data: stores } } : undefined } })