Phase 2 — Schema & Migration Split #107
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#107
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 2 — Schema & Migration Split
Type: Architecture / Refactoring
Priority: High
Epic: Epic: Database-per-Club Multi-Tenancy Split & Data Migration
Status: Backlog
1. Context & Purpose
We need to separate the schema migrations list into system-wide central migrations and club-specific tenant migrations. This allows the system to initialize the Central Database first, and then dynamically create and migrate each club's dedicated database.
2. Technical Specification
2.1. Migration Definitions Split (
migrations.py)Modify app/infrastructure/database/migrations.py:
CENTRAL_MIGRATIONS: Contains migrations that apply to central tables:migration_ensure_clubs_table(if defined, or other club-list tables)migration_add_timezone_field(onclubs)migration_add_created_updated_timestamps(onclubs)migration_add_user_club_assignments_tablemigration_add_api_tokens_table(since tokens are checked centrally)oauth2_configtablesuserstableCLUB_MIGRATIONS: Contains migrations that apply to club-specific tables:memberstable creationfamiliestable creationattendancetable creationbelt_levelstable creationgradingstable creationclass_schedulestable creationnotes_historytable creationform_configurationstable creationcontent_itemsandcontent_club_approvals(CMS content is local to each club)family_guardianstable creation2.2. Clubs Database Routing Metadata
CENTRAL_MIGRATIONSto add a newdatabase_namecolumn to theclubstable if it does not already exist:2.3. Dynamic Migration Execution Flow
Update
run_all_migrations(engine)inmigrations.py:engine.CENTRAL_MIGRATIONSagainst that central database engine.clubstable for all clubs with a non-nulldatabase_name.honbu_club_<id>using the default database URL parameters but swapping the database name to the club's specific database.CLUB_MIGRATIONSon that club database engine.2.4. New Club Registration Flow (
club_ops.py)Update
ClubOperations.create_clubin app/core/operations/club_ops.py:clubstable.database_nametohonbu_club_<id>.postgresdefault database), executeCREATE DATABASE honbu_club_<id>.run_migrationswithCLUB_MIGRATIONS, and commit.3. Verification Plan
3.1. Automated Unit Tests
Write tests in
tests/unit/test_migrations_split.py:run_all_migrationswith no clubs registered only creates Central tables.database_namecausesrun_all_migrationsto attempt connection and schema creation on that database.3.2. Integration Verification
Part of Epic #105