feat(jobs/runners): attachment cleanup + chat DeleteAttachments query/method

This commit is contained in:
2026-05-06 08:07:49 +08:00
parent c50621eeca
commit f56fe449fd
7 changed files with 193 additions and 0 deletions
+3
View File
@@ -30,3 +30,6 @@ JOIN messages m ON m.id = a.message_id
JOIN conversations c ON c.id = m.conversation_id
WHERE c.deleted_at IS NOT NULL
AND c.deleted_at < NOW() - ($1::interval);
-- name: DeleteAttachmentsByIDs :exec
DELETE FROM message_attachments WHERE id = ANY($1::uuid[]);
+15
View File
@@ -58,6 +58,7 @@ type Repository interface {
ListExpiredOrphans(ctx context.Context, olderThan time.Duration) ([]AttachmentRef, error)
ListAttachmentsForSoftDeletedConversations(ctx context.Context, olderThan time.Duration) ([]AttachmentRef, error)
DeleteAttachment(ctx context.Context, id uuid.UUID) error
DeleteAttachments(ctx context.Context, ids []uuid.UUID) error
// ===== PromptTemplate =====
InsertPromptTemplate(ctx context.Context, p InsertTemplateParams) (*PromptTemplate, error)
@@ -778,6 +779,20 @@ func (r *pgRepo) DeleteAttachment(ctx context.Context, id uuid.UUID) error {
return nil
}
func (r *pgRepo) DeleteAttachments(ctx context.Context, ids []uuid.UUID) error {
if len(ids) == 0 {
return nil
}
pgIDs := make([]pgtype.UUID, len(ids))
for i, id := range ids {
pgIDs[i] = toPgUUID(id)
}
if err := r.q.DeleteAttachmentsByIDs(ctx, pgIDs); err != nil {
return errs.Wrap(err, errs.CodeInternal, "delete attachments")
}
return nil
}
// ===== PromptTemplate =====
func (r *pgRepo) InsertPromptTemplate(ctx context.Context, p InsertTemplateParams) (*PromptTemplate, error) {
+3
View File
@@ -244,6 +244,9 @@ func (f *fakeRepo) ListAttachmentsForSoftDeletedConversations(_ context.Context,
panic("not implemented")
}
func (f *fakeRepo) DeleteAttachment(_ context.Context, _ uuid.UUID) error { panic("not implemented") }
func (f *fakeRepo) DeleteAttachments(_ context.Context, _ []uuid.UUID) error {
panic("not implemented")
}
func (f *fakeRepo) InsertPromptTemplate(_ context.Context, _ InsertTemplateParams) (*PromptTemplate, error) {
panic("not implemented")
}
+9
View File
@@ -34,6 +34,15 @@ func (q *Queries) DeleteAttachment(ctx context.Context, id pgtype.UUID) error {
return err
}
const deleteAttachmentsByIDs = `-- name: DeleteAttachmentsByIDs :exec
DELETE FROM message_attachments WHERE id = ANY($1::uuid[])
`
func (q *Queries) DeleteAttachmentsByIDs(ctx context.Context, dollar_1 []pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteAttachmentsByIDs, dollar_1)
return err
}
const getAttachment = `-- name: GetAttachment :one
SELECT id, user_id, message_id, filename, mime_type, size_bytes, sha256, storage_path, created_at FROM message_attachments WHERE id = $1
`
+3
View File
@@ -207,6 +207,9 @@ func (panicRepo) ListAttachmentsForSoftDeletedConversations(_ context.Context, _
panic("not implemented")
}
func (panicRepo) DeleteAttachment(_ context.Context, _ uuid.UUID) error { panic("not implemented") }
func (panicRepo) DeleteAttachments(_ context.Context, _ []uuid.UUID) error {
panic("not implemented")
}
func (panicRepo) InsertPromptTemplate(_ context.Context, _ InsertTemplateParams) (*PromptTemplate, error) {
panic("not implemented")
}