feat(db-split): Phase 3 — Repository Refactoring & Cross-DB Gaps (#108) #113

Open
fastie81 wants to merge 8 commits from feature/db-split-phase3-refactoring into main
Owner

This Pull Request implements Phase 3 — Repository Refactoring & Cross-DB Gaps (#108).

Proposed Changes

Component 1: DashboardOperations Refactoring

  • Decoupled DashboardOperations from raw connection wrapper; injected club_repo and system_repo in app/container.py.
  • Aggregates member count across multiple routed databases under their respective club context in get_system_stats().
  • Implemented club timezone calculations for upcoming birthdays using get_current_date_in_club_timezone in get_club_dashboard_data().
  • Wrapped all dashboard API calls and methods in active club routing.

Component 2: System Repository Cross-DB Fixes

  • Two-Phase Queries:
    • get_users_by_club(): Fetches user IDs in club DB, then resolves profiles in central DB.
    • get_family_guardians(): Fetches guardian user IDs in club DB, then details in central DB.
    • get_available_guardians(): Combines candidate member user IDs, filters current guardians, and resolves details in central DB.
  • Cascading Deletions:
    • delete_user(): Cascades cleanups of user references across all club databases before deleting the record from the Central DB.
    • delete_club(): Creates an on-disk JSON backup under the club context first, terminates active backend pg connections, and then drops the database.

Component 3: Application-Level FK Validation

  • Added check in create_member() and update_member() to ensure user IDs exist in Central DB.
  • Added check in add_guardian_to_family() to ensure the user ID exists, and automatically registers the user with a 'Member' role assignment for that club in the Central DB.

Component 5: Tests

  • Created test_dashboard_split.py to assert correct routing context manager stack.
  • Created test_user_lookups.py to assert two-phase queries return identical structures.
  • Created test_fk_validation.py to assert ValueErrors on non-existent users.

All unit and E2E controller tests pass successfully.

This Pull Request implements Phase 3 — Repository Refactoring & Cross-DB Gaps (#108). ### Proposed Changes #### Component 1: DashboardOperations Refactoring - Decoupled `DashboardOperations` from raw connection wrapper; injected `club_repo` and `system_repo` in `app/container.py`. - Aggregates member count across multiple routed databases under their respective club context in `get_system_stats()`. - Implemented club timezone calculations for upcoming birthdays using `get_current_date_in_club_timezone` in `get_club_dashboard_data()`. - Wrapped all dashboard API calls and methods in active club routing. #### Component 2: System Repository Cross-DB Fixes - **Two-Phase Queries**: - `get_users_by_club()`: Fetches user IDs in club DB, then resolves profiles in central DB. - `get_family_guardians()`: Fetches guardian user IDs in club DB, then details in central DB. - `get_available_guardians()`: Combines candidate member user IDs, filters current guardians, and resolves details in central DB. - **Cascading Deletions**: - `delete_user()`: Cascades cleanups of user references across all club databases before deleting the record from the Central DB. - `delete_club()`: Creates an on-disk JSON backup under the club context first, terminates active backend pg connections, and then drops the database. #### Component 3: Application-Level FK Validation - Added check in `create_member()` and `update_member()` to ensure user IDs exist in Central DB. - Added check in `add_guardian_to_family()` to ensure the user ID exists, and automatically registers the user with a 'Member' role assignment for that club in the Central DB. #### Component 5: Tests - Created `test_dashboard_split.py` to assert correct routing context manager stack. - Created `test_user_lookups.py` to assert two-phase queries return identical structures. - Created `test_fk_validation.py` to assert ValueErrors on non-existent users. All unit and E2E controller tests pass successfully.
Phase 1: Dynamic Routing Infrastructure (#106)
All checks were successful
CI / test (push) Successful in 5m53s
CI / lint-frontend (push) Successful in 2m8s
0e6b0b009b
Fix issues raised in Phase 1 implementation review
All checks were successful
CI / test (push) Successful in 5m25s
CI / lint-frontend (push) Successful in 1m56s
a5e85edc97
Fix deadlock risk in get_engine and fix test mock URL setup
All checks were successful
CI / test (push) Successful in 5m51s
CI / lint-frontend (push) Successful in 2m2s
eb22e7a46d
- Adds Docker image build and push to registry on successful CI
- Uses forgejo.repository_owner and forgejo.token for auth
- Tags: branch refs, semver versions, and latest on main branch
- Depends on test job to ensure only validated images are pushed
- Restores original docker-compose.yml with clean build configuration
- Adds docker-compose.registry.yml for pulling pre-built images from Forgejo registry
- Use: docker-compose -f docker-compose.yml -f docker-compose.registry.yml up -d
This override file configures docker-compose to pull images from the
Forgejo container registry instead of building locally.

Usage on server:
  docker login forgejo.scrat.co.nz
  docker-compose -f docker-compose.yml -f docker-compose.registry.yml up -d
feat(db-split): separate central and club migrations with dynamic tenant DB provisioning and security guards
Some checks failed
ci.yml / feat(db-split): separate central and club migrations with dynamic tenant DB provisioning and security guards (push) Failing after 0s
ci.yml / feat(db-split): separate central and club migrations with dynamic tenant DB provisioning and security guards (pull_request) Failing after 0s
790548d6e3
feat(db-split): Phase 3 — Repository Refactoring & Cross-DB Gaps (#108)
Some checks failed
ci.yml / feat(db-split): Phase 3 — Repository Refactoring & Cross-DB Gaps (#108) (push) Failing after 0s
ci.yml / feat(db-split): Phase 3 — Repository Refactoring & Cross-DB Gaps (#108) (pull_request) Failing after 0s
9a27db2558
Some checks are pending
ci.yml / feat(db-split): Phase 3 — Repository Refactoring & Cross-DB Gaps (#108) (push) Failing after 0s
ci.yml / feat(db-split): Phase 3 — Repository Refactoring & Cross-DB Gaps (#108) (pull_request) Failing after 0s
CI / test (pull_request)
Required
CI / lint-frontend (pull_request)
Required
This pull request has changes conflicting with the target branch.
  • .forgejo/workflows/ci.yml
  • docker-compose.test.yml
  • docker-compose.yml
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/db-split-phase3-refactoring:feature/db-split-phase3-refactoring
git switch feature/db-split-phase3-refactoring
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
fastie81/honbu-manager!113
No description provided.