Skip to content

feat: DynamoDB single-table design pattern - #9

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

feat: DynamoDB single-table design pattern#9
maxsonferovante wants to merge 4 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
@bentoluizv

Copy link
Copy Markdown
Contributor

Esse PR reintroduz o cpf/cidade removidos no #8:

  • :143 get_by_cpf · :157 get_by_city · :178 cpf_exists
  • :197-198 if city: item["GSI5PK"] = f"CITY#{city}"
  • dynamodb_keys.py:72 gsi4pk_city

Tira esses? Junto com o GSI5 no py-certify-infra#64.

- Remove get_by_cpf method
- Remove get_by_city method
- Remove cpf_exists method
- Remove GSI5PK/GSI5SK from _prepare_item
- Remove gsi4pk_city and gsi4sk_participant from dynamodb_keys
- Update integration test to remove city lookup
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.

2 participants