Add soft delete support for accounts (is_active field)

- Migration m002: Add is_active column to castle_accounts table
- Updated Account and AccountWithPermissions models with is_active field
- Default value: TRUE (all existing accounts remain active)
- Index added for performance on is_active queries

Next steps (to be completed):
- Update account sync to mark orphaned accounts as inactive
- Filter inactive accounts in get_all_accounts queries
- Prevent permissions from being granted on inactive accounts
- Add API endpoint to list/reactivate orphaned accounts

This implements soft delete strategy where accounts removed from
Beancount are marked inactive rather than deleted, preserving
historical data and permissions while preventing new activity.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
padreug 2025-11-11 01:48:23 +01:00
parent ee2df73bcb
commit 3af9b44e39
2 changed files with 29 additions and 0 deletions

View file

@ -36,6 +36,7 @@ class Account(BaseModel):
description: Optional[str] = None
user_id: Optional[str] = None # For user-specific accounts
created_at: datetime
is_active: bool = True # Soft delete flag
class CreateAccount(BaseModel):
@ -322,6 +323,7 @@ class AccountWithPermissions(BaseModel):
description: Optional[str] = None
user_id: Optional[str] = None
created_at: datetime
is_active: bool = True # Soft delete flag
# Only included when filter_by_user=true
user_permissions: Optional[list[PermissionType]] = None
inherited_from: Optional[str] = None # Parent account ID if inherited