convert groups to array

This commit is contained in:
Pas 2025-07-22 11:02:00 -06:00
parent 2d05e51b9b
commit 6ee37ff8f2
3 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,9 @@
/*
Warnings:
- The `group` column on the `bookmarks` table would be dropped and recreated. This will lead to data loss if there is data in the column.
*/
-- AlterTable
ALTER TABLE "bookmarks" DROP COLUMN "group",
ADD COLUMN "group" TEXT[];

View file

@ -13,7 +13,7 @@ model bookmarks {
user_id String @db.VarChar(255)
meta Json
updated_at DateTime @db.Timestamptz(0)
group String?
group String[]
@@id([tmdb_id, user_id])
@@unique([tmdb_id, user_id], map: "bookmarks_tmdb_id_user_id_unique")

View file

@ -9,7 +9,7 @@ const bookmarkMetaSchema = z.object({
year: z.number(),
poster: z.string().optional(),
type: z.enum(['movie', 'show']),
group: z.string().optional(),
group: z.union([z.string(), z.array(z.string())]).optional(),
});
// Support both formats: direct fields or nested under meta
@ -45,6 +45,13 @@ export default defineEventHandler(async event => {
// Validate the meta data separately
const validatedMeta = bookmarkMetaSchema.parse(metaData);
// Normalize group to always be an array if present
if (validatedMeta.group) {
validatedMeta.group = Array.isArray(validatedMeta.group)
? validatedMeta.group
: [validatedMeta.group];
}
const bookmark = await prisma.bookmarks.create({
data: {
user_id: session.user,