feat: Phase 1 Group 8 — add account_id to target_lists (keep team_id)
Zero rows in production — this is a schema-only migration in practice. team_id kept for app code compatibility. Drop deferred to later cleanup. Backfill: team_id → team admin user → account_id; fallback: created_by. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -443,3 +443,38 @@ async def test_script_builder_session_account_id(test_db: AsyncSession):
|
||||
)
|
||||
row = result.scalar_one()
|
||||
assert row.account_id == account.id
|
||||
|
||||
|
||||
# ── Group 8: TargetList ────────────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_target_list_account_id_from_team_admin(test_db: AsyncSession):
|
||||
"""target_lists.account_id must be set to the team admin's account_id."""
|
||||
from app.models.target_list import TargetList
|
||||
from app.models.team import Team
|
||||
|
||||
account, user = await _make_account_and_user(test_db, "tl1")
|
||||
# Make user a team admin
|
||||
team = Team(name=f"Team {uuid.uuid4().hex[:6]}")
|
||||
test_db.add(team)
|
||||
await test_db.flush()
|
||||
|
||||
user.team_id = team.id
|
||||
user.is_team_admin = True
|
||||
await test_db.flush()
|
||||
|
||||
target_list = TargetList(
|
||||
team_id=team.id,
|
||||
account_id=account.id,
|
||||
created_by=user.id,
|
||||
name="Server Targets",
|
||||
targets=[{"label": "SRV-01"}],
|
||||
)
|
||||
test_db.add(target_list)
|
||||
await test_db.commit()
|
||||
|
||||
result = await test_db.execute(
|
||||
select(TargetList).where(TargetList.id == target_list.id)
|
||||
)
|
||||
row = result.scalar_one()
|
||||
assert row.account_id == account.id
|
||||
|
||||
Reference in New Issue
Block a user