fix(models,dao): media_items unique key includes mountId
This commit is contained in:
parent
3af8ebead7
commit
e65acd1e9c
|
|
@ -43,11 +43,21 @@ export const mediaItemDao = {
|
|||
.limit(1);
|
||||
return row ?? null;
|
||||
},
|
||||
async getByUserPath(userId: string, path: string): Promise<MediaItemRow | null> {
|
||||
async getByUserPath(
|
||||
userId: string,
|
||||
mountId: string,
|
||||
path: string,
|
||||
): Promise<MediaItemRow | null> {
|
||||
const [row] = await db
|
||||
.select()
|
||||
.from(mediaItems)
|
||||
.where(and(eq(mediaItems.userId, userId), eq(mediaItems.path, path)))
|
||||
.where(
|
||||
and(
|
||||
eq(mediaItems.userId, userId),
|
||||
eq(mediaItems.mountId, mountId),
|
||||
eq(mediaItems.path, path),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
return row ?? null;
|
||||
},
|
||||
|
|
@ -60,11 +70,12 @@ export const mediaItemDao = {
|
|||
size: number;
|
||||
mime?: string | undefined;
|
||||
}): Promise<MediaItemRow> {
|
||||
const existing = await this.getByUserPath(data.userId, data.path);
|
||||
const existing = await this.getByUserPath(data.userId, data.mountId, data.path);
|
||||
if (existing) {
|
||||
const [row] = await db
|
||||
.update(mediaItems)
|
||||
.set({
|
||||
mountId: data.mountId,
|
||||
size: data.size,
|
||||
mime: data.mime,
|
||||
updatedAt: new Date(),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export const mediaItems = sqliteTable(
|
|||
.notNull()
|
||||
.default(sql`(unixepoch())`),
|
||||
},
|
||||
(t) => [uniqueIndex("media_user_path_uq").on(t.userId, t.path)],
|
||||
(t) => [uniqueIndex("media_user_mount_path_uq").on(t.userId, t.mountId, t.path)],
|
||||
);
|
||||
export type MediaItem = typeof mediaItems.$inferSelect;
|
||||
export type NewMediaItem = typeof mediaItems.$inferInsert;
|
||||
|
|
|
|||
Loading…
Reference in New Issue