mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
fix: foreign key issue with thumbnails (#824)
This commit is contained in:
@@ -176,7 +176,7 @@ tasks:
|
||||
cmds:
|
||||
- cd backend && go build ./app/api
|
||||
- backend/api &
|
||||
- sleep 10
|
||||
- sleep 15
|
||||
- cd frontend && pnpm run test:ci
|
||||
silent: true
|
||||
|
||||
@@ -193,7 +193,7 @@ tasks:
|
||||
cmds:
|
||||
- cd backend && go build ./app/api
|
||||
- backend/api &
|
||||
- sleep 10
|
||||
- sleep 15
|
||||
- cd frontend && pnpm run test:ci
|
||||
silent: true
|
||||
|
||||
|
||||
@@ -350,8 +350,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
|
||||
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
|
||||
@@ -375,8 +373,6 @@ github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJm
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/olahol/melody v1.2.1 h1:xdwRkzHxf+B0w4TKbGpUSSkV516ZucQZJIWLztOWICQ=
|
||||
github.com/olahol/melody v1.2.1/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/onsi/ginkgo/v2 v2.9.2 h1:BA2GMJOtfGAfagzYtrAlufIP0lq6QERkFmHLMLPwFSU=
|
||||
github.com/onsi/ginkgo/v2 v2.9.2/go.mod h1:WHcJJG2dIlcCqVfBAwUCrJxSPFb6v4azBwgxeMeDuts=
|
||||
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
|
||||
@@ -417,10 +413,6 @@ github.com/shirou/gopsutil/v4 v4.25.5 h1:rtd9piuSMGeU8g1RMXjZs9y9luK5BwtnG7dZaQU
|
||||
github.com/shirou/gopsutil/v4 v4.25.5/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
|
||||
@@ -55,7 +55,7 @@ func (svc *ItemService) AttachmentAdd(ctx Context, itemID uuid.UUID, filename st
|
||||
return svc.repo.Items.GetOneByGroup(ctx, ctx.GID, itemID)
|
||||
}
|
||||
|
||||
func (svc *ItemService) AttachmentDelete(ctx context.Context, gid, itemID, attachmentID uuid.UUID) error {
|
||||
func (svc *ItemService) AttachmentDelete(ctx context.Context, gid uuid.UUID, id uuid.UUID, attachmentID uuid.UUID) error {
|
||||
// Delete the attachment
|
||||
err := svc.repo.Attachments.Delete(ctx, attachmentID)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
-- +goose Up
|
||||
alter table public.attachments
|
||||
drop constraint attachments_attachments_thumbnail;
|
||||
|
||||
alter table public.attachments
|
||||
add constraint attachments_attachments_thumbnail
|
||||
foreign key (attachment_thumbnail) references public.attachments
|
||||
on delete set null;
|
||||
@@ -0,0 +1,45 @@
|
||||
-- +goose Up
|
||||
create table attachments_dg_tmp
|
||||
(
|
||||
id uuid not null
|
||||
primary key,
|
||||
created_at datetime not null,
|
||||
updated_at datetime not null,
|
||||
type text default 'attachment' not null,
|
||||
"primary" bool default false not null,
|
||||
path text not null,
|
||||
title text not null,
|
||||
mime_type text default 'application/octet-stream' not null,
|
||||
item_attachments uuid
|
||||
constraint attachments_items_attachments
|
||||
references items
|
||||
on delete cascade,
|
||||
attachment_thumbnail uuid
|
||||
constraint attachments_attachments_thumbnail
|
||||
references attachments
|
||||
on delete set null
|
||||
);
|
||||
|
||||
insert into attachments_dg_tmp(id, created_at, updated_at, type, "primary", path, title, mime_type, item_attachments,
|
||||
attachment_thumbnail)
|
||||
select id,
|
||||
created_at,
|
||||
updated_at,
|
||||
type,
|
||||
"primary",
|
||||
path,
|
||||
title,
|
||||
mime_type,
|
||||
item_attachments,
|
||||
attachment_thumbnail
|
||||
from attachments;
|
||||
|
||||
drop table attachments;
|
||||
|
||||
alter table attachments_dg_tmp
|
||||
rename to attachments;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_attachments_item_id ON attachments(item_attachments);
|
||||
CREATE INDEX IF NOT EXISTS idx_attachments_path ON attachments(path);
|
||||
CREATE INDEX IF NOT EXISTS idx_attachments_type ON attachments(type);
|
||||
CREATE INDEX IF NOT EXISTS idx_attachments_thumbnail ON attachments(attachment_thumbnail);
|
||||
@@ -316,6 +316,28 @@ func (r *AttachmentRepo) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
}
|
||||
// If this is the last attachment for this path, delete the file
|
||||
if len(all) == 1 {
|
||||
thumb, err := doc.QueryThumbnail().First(ctx)
|
||||
if err != nil && !ent.IsNotFound(err) {
|
||||
log.Err(err).Msg("failed to query thumbnail for attachment")
|
||||
return err
|
||||
}
|
||||
if thumb != nil {
|
||||
thumbBucket, err := blob.OpenBucket(ctx, r.GetConnString())
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to open bucket for thumbnail deletion")
|
||||
return err
|
||||
}
|
||||
err = thumbBucket.Delete(ctx, thumb.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = doc.Update().SetNillableThumbnailID(nil).SaveX(ctx)
|
||||
_ = thumb.Update().SetNillableThumbnailID(nil).SaveX(ctx)
|
||||
err = r.db.Attachment.DeleteOneID(thumb.ID).Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
bucket, err := blob.OpenBucket(ctx, r.GetConnString())
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to open bucket")
|
||||
|
||||
@@ -57,7 +57,7 @@ function filterOutSubtree(tree: TreeItem[], excludeId: string): TreeItem[] {
|
||||
|
||||
export function useFlatLocations(excludeSubtreeForLocation?: LocationSummary): Ref<FlatTreeItem[]> {
|
||||
const locations = useLocationStore();
|
||||
|
||||
|
||||
if (locations.tree === null) {
|
||||
locations.refreshTree();
|
||||
}
|
||||
|
||||
@@ -509,11 +509,7 @@
|
||||
<MdiSelectSearch class="size-10" />
|
||||
<p>{{ $t("items.no_results") }}</p>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
ref="cardgrid"
|
||||
class="mt-4 grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4"
|
||||
>
|
||||
<div v-else ref="cardgrid" class="mt-4 grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
|
||||
<ItemCard v-for="item in items" :key="item.id" :item="item" :location-flat-tree="locationFlatTree" />
|
||||
</div>
|
||||
<Pagination
|
||||
|
||||
Reference in New Issue
Block a user