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);
|
.limit(1);
|
||||||
return row ?? null;
|
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
|
const [row] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(mediaItems)
|
.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);
|
.limit(1);
|
||||||
return row ?? null;
|
return row ?? null;
|
||||||
},
|
},
|
||||||
|
|
@ -60,11 +70,12 @@ export const mediaItemDao = {
|
||||||
size: number;
|
size: number;
|
||||||
mime?: string | undefined;
|
mime?: string | undefined;
|
||||||
}): Promise<MediaItemRow> {
|
}): Promise<MediaItemRow> {
|
||||||
const existing = await this.getByUserPath(data.userId, data.path);
|
const existing = await this.getByUserPath(data.userId, data.mountId, data.path);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
const [row] = await db
|
const [row] = await db
|
||||||
.update(mediaItems)
|
.update(mediaItems)
|
||||||
.set({
|
.set({
|
||||||
|
mountId: data.mountId,
|
||||||
size: data.size,
|
size: data.size,
|
||||||
mime: data.mime,
|
mime: data.mime,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export const mediaItems = sqliteTable(
|
||||||
.notNull()
|
.notNull()
|
||||||
.default(sql`(unixepoch())`),
|
.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 MediaItem = typeof mediaItems.$inferSelect;
|
||||||
export type NewMediaItem = typeof mediaItems.$inferInsert;
|
export type NewMediaItem = typeof mediaItems.$inferInsert;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue