server icon indicating copy to clipboard operation
server copied to clipboard

Refactor StorageBucketService to handle document-bucket relationships safely

Open coderabbitai[bot] opened this issue 10 months ago • 0 comments
trafficstars

Problem

The current implementation in StorageBucketService allows saving documents before saving storage buckets, which can lead to implicit behavior based on TypeORM entity relationships.

Impact

  • If a storage bucket is not saved before its documents, the relationship between them may not be persisted correctly.
  • This can result in orphaned documents or missing relationships in the database.
  • The behavior depends on cascade settings and relationship types, making it less predictable.

Context

  • PR Discussion: https://github.com/alkem-io/server/pull/4763#discussion_r1878297104
  • Related file: src/domain/storage/storage-bucket/storage.bucket.service.ts

Proposed Solution

Ensure that storage buckets are always saved before their associated documents to maintain data integrity and explicit behavior.

Tasks

  1. Review and document all places where documents are saved in relation to storage buckets
  2. Implement proper validation to ensure storage buckets exist before saving documents
  3. Consider adding transaction support for atomic operations
  4. Update tests to verify correct relationship persistence

coderabbitai[bot] avatar Jan 20 '25 10:01 coderabbitai[bot]