Skip to content

feat: DynamoDB single-table design pattern - #9

Open
maxsonferovante wants to merge 2 commits into
masterfrom
feature/single-table-dynamodb
Open

feat: DynamoDB single-table design pattern#9
maxsonferovante wants to merge 2 commits into
masterfrom
feature/single-table-dynamodb

Conversation

@maxsonferovante

Copy link
Copy Markdown
Contributor

Summary

Implements DynamoDB Single-Table design pattern, replacing 4 separate tables (orders, certificates, products, participants) with a single table based on AWS best practices.

Changes

  • dynamodb_keys.py: Add PK/SK/GSI key generation helpers for single-table pattern
  • Repositories refactored:
    • OrderRepository: GSI2 (email), GSI3 (product)
    • CertificateRepository: GSI1 (UUID), GSI2 (email), GSI3 (product), GSI4 (success)
    • ProductRepository: GSI3 (name)
    • ParticipantRepository: GSI2 (email), GSI5 (city)
  • EntityType filter: Added to all GSI queries to prevent cross-entity returns
  • get_all(): Uses scan with EntityType filter instead of invalid query
  • config.py: Returns single table name
  • dependency_container.py: No longer passes table_name to repositories
  • Tests: Unit tests (9/9 passing) + integration test for CRUD operations

GSI Design

GSI Access Pattern
GSI1 Certificate by UUID
GSI2 Orders, Certificates, Participants by email
GSI3 Products by name, Certificates/Orders by product
GSI4 Successful certificates
GSI5 Participants by city

Tested

End-to-end integration tests with MiniStack (local DynamoDB) passing.

- Add dynamodb_keys.py with PK/SK/GSI key generation helpers
- Refactor all 4 repositories for single-table design:
  - OrderRepository: GSI2 (email), GSI3 (product)
  - CertificateRepository: GSI1 (UUID), GSI2 (email), GSI3 (product), GSI4 (success)
  - ProductRepository: GSI3 (name)
  - ParticipantRepository: GSI2 (email), GSI5 (city)
- Add EntityType filter to GSI queries to prevent cross-entity returns
- Add get_all() using scan with EntityType filter
- Update config to return single table name
- Update dependency_container to not pass table_name to repositories
- Add integration test for single-table CRUD operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant