mirror of
https://github.com/p-stream/backend.git
synced 2026-03-11 17:55:35 +00:00
convert groups to array
This commit is contained in:
parent
2d05e51b9b
commit
6ee37ff8f2
3 changed files with 18 additions and 2 deletions
|
|
@ -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[];
|
||||||
|
|
@ -13,7 +13,7 @@ model bookmarks {
|
||||||
user_id String @db.VarChar(255)
|
user_id String @db.VarChar(255)
|
||||||
meta Json
|
meta Json
|
||||||
updated_at DateTime @db.Timestamptz(0)
|
updated_at DateTime @db.Timestamptz(0)
|
||||||
group String?
|
group String[]
|
||||||
|
|
||||||
@@id([tmdb_id, user_id])
|
@@id([tmdb_id, user_id])
|
||||||
@@unique([tmdb_id, user_id], map: "bookmarks_tmdb_id_user_id_unique")
|
@@unique([tmdb_id, user_id], map: "bookmarks_tmdb_id_user_id_unique")
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ const bookmarkMetaSchema = z.object({
|
||||||
year: z.number(),
|
year: z.number(),
|
||||||
poster: z.string().optional(),
|
poster: z.string().optional(),
|
||||||
type: z.enum(['movie', 'show']),
|
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
|
// Support both formats: direct fields or nested under meta
|
||||||
|
|
@ -45,6 +45,13 @@ export default defineEventHandler(async event => {
|
||||||
// Validate the meta data separately
|
// Validate the meta data separately
|
||||||
const validatedMeta = bookmarkMetaSchema.parse(metaData);
|
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({
|
const bookmark = await prisma.bookmarks.create({
|
||||||
data: {
|
data: {
|
||||||
user_id: session.user,
|
user_id: session.user,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue