Handle deletion cascade (organizations, cameras, poses, sequences, alerts) and storage cleanup

Đang mở
#541 5 bình luận 1 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 7 ngày

@Majyles đang làm issue này rồi.

Từ ngày 9/11/2026.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
fastapi, postgresql, python
Lĩnh vực
backend, cloud, database

Hướng nghiên cứu

Xem xét PR #538 và quy trình xóa organization xoay quanh organizations.session, bao gồm cả việc xóa liên kết alert được hiển thị trong issue. Theo dõi mối quan hệ giữa camera, pose, sequence, detection và media S3 liên quan với organization và các ràng buộc foreign-key của nó. Hoàn tất có nghĩa là việc xóa organization sẽ xóa tất cả các bản ghi và media được liệt kê mà không để lại dữ liệu mồ côi, đồng thời hoàn thành coverage test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

endpoint: organizations module: database

Description
Deleting an organization currently only removes alerts in order to satisfy foreign key constraints. Cameras, poses, sequences, detections, and associated media stored in S3 are not deleted. This leaves orphaned data and makes the data lifecycle unclear.

Before alerts were handled, deletion was already incomplete for cameras and related objects, so this issue existed even earlier and is not specific to alerts only.

I started addressing this partially in PR #538 by explicitly deleting alerts and their association tables, but coverage test became quite comple so I stopped for this PR and opened this issue to address it properly later

# Remove alerts and their associations for this organization to satisfy FK constraints
org_session = organizations.session
alert_ids_res = await org_session.exec(
    select(Alert.id).where(Alert.organization_id == organization_id)
)
alert_ids = list(alert_ids_res.all())

if alert_ids:
    delete_links = delete(AlertSequence).where(
        cast(Any, AlertSequence.alert_id).in_(alert_ids)
    )
    delete_alerts = delete(Alert).where(
        cast(Any, Alert.id).in_(alert_ids)
    )
    await org_session.exec(delete_links)
    await org_session.exec(delete_alerts)
    await org_session.commit()
Ngôn ngữ chính
Python
Star
31
Fork
15
Merge trung bình
7 ngày 18 giờ
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pyronear/pyro-api

Tất cả issue của pyronear/pyro-api

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.