Phase 3 — Repository Refactoring & Cross-DB Gaps #108
Labels
No labels
architecture
backend
bug
ci
config
database
docker
documentation
duplicate
enhancement
frontend
help wanted
invalid
issue-25
issue-26
issue-42
issue-65
issue-67
issue-82
migrations
p0-critical
p1-high
p2-medium
p3-low
performance
quality
question
security
state-management
testing
timezone
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
fastie81/honbu-manager#108
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Issue: Phase 3 — Repository Refactoring & Cross-DB Gaps
Type: Architecture / Refactoring
Priority: High
Epic: Epic: Database-per-Club Multi-Tenancy Split & Data Migration
Status: Backlog
1. Context & Purpose
Because tables will be split across separate databases, direct SQL
JOINs between central-only tables (users,clubs) and club-specific tables (members,families) are physically impossible. Similarly, code using raw db connection wrappers bypassing operations/repositories will fail. This issue refactors all affected queries and modules to resolve these architectural gaps.2. Technical Specification
2.1. Refactor
DashboardOperationsModify app/core/operations/dashboard_ops.py:
__init__(self, db_wrapper):club_repoandsystem_repoinstead:__init__(self, club_repo, system_repo).DashboardOperationsto use the appropriate repository:club_repo.system_repo.app/container.pydependency wiring to match:2.2. Fix
get_system_stats()Modify
get_system_stats()inDashboardOperations:SELECT COUNT(*) FROM membersagainst a single database (which would return 0 on the Central database), it must:system_repo.get_all_clubs().with route_to_club(club.id):.SELECT COUNT(*) FROM membersinside that context.2.3. Eliminate Cross-DB JOIN in
get_users_by_club()Modify
get_users_by_club(club_id)in app/core/repositories/postgres_system_repo.py:users,user_club_assignments,family_guardians,families, andmembersin a single query. Update it to be a two-phase query:club_repoor setting routing context):user_idvalues from thememberstable.user_idvalues from thefamily_guardianstable.user_ids.user_idvalues fromuser_club_assignmentswhereclub_id = :cid.userstable for all found IDs usingWHERE id = ANY(:ids).System Admin.2.4. Refactor
delete_club()Modify
delete_club(club_id)inpostgres_system_repo.py:honbu_club_<club_id>.postgresdefault database) and executeDROP DATABASE IF EXISTS honbu_club_<club_id>to delete all member, family, attendance, grading, and note records cleanly and atomically.user_club_assignmentsandapi_tokensassociated with this club.clubs.2.5. Implement Application-level Foreign Key Validation
create_member(member_data)inMemberOperations:user_idis supplied inmember_data, verify it exists in the Central Database by queryingsystem_repo.get_user(user_id). Raise a validation error if not found.add_guardian(family_id, user_id)inFamilyOperations:user_idexists in the Central Database before inserting the association infamily_guardianstable.2.6. Birthday Timezone Fix (Co-resolved from Issue #96 / #82)
DashboardOperations.get_club_dashboard_data.3. Verification Plan
3.1. Automated Unit Tests
tests/unit/test_dashboard_split.pyto ensureDashboardOperationscorrectly routes statistics calls and aggregates member counts across multiple mock database engines.tests/unit/test_user_lookups.pyensuring the two-phase query inget_users_by_clubreturns exact matches identical to the old joined query.user_idcorrectly throws a validation error.3.2. Integration Verification
Part of Epic #105
Phase 3 has been fully implemented, verified, and tested. Staged unit tests and E2E tests are 100% green.
Opened Pull Request: #113.