infrastructure.persistence.models.account¶
src.infrastructure.persistence.models.account
¶
Account database model.
This module defines the Account model for storing financial account data synced from provider connections.
Architecture
- Accounts belong to provider connections (FK relationship)
- Balance stored as Decimal with separate currency column
- Account type stored as lowercase string
- Provider metadata stored as JSONB for flexibility
Reference
- docs/architecture/account-domain-model.md
- docs/architecture/repository-pattern.md
Classes¶
Account
¶
Bases: BaseMutableModel
Account model for financial account storage.
Represents a financial account (brokerage, checking, IRA, etc.) aggregated from a provider connection.
Fields
id: UUID primary key (from BaseMutableModel) created_at: Timestamp when created (from BaseMutableModel) updated_at: Timestamp when last updated (from BaseMutableModel) connection_id: FK to provider_connections table provider_account_id: Provider's unique account identifier account_number_masked: Masked account number (**1234) name: Account name from provider account_type: Type (brokerage, checking, ira, etc.) balance: Current balance amount (Decimal) currency: ISO 4217 currency code available_balance: Available balance if different (nullable) is_active: Whether account is active on provider last_synced_at: Last successful sync timestamp provider_metadata: Provider-specific data (JSONB)
Indexes
- ix_accounts_connection_id: FK lookup
- ix_accounts_account_type: Filter by type
- ix_accounts_is_active: Active account queries
- idx_accounts_active: Partial index for active accounts (optimization)
- uq_accounts_connection_provider: Unique (connection_id, provider_account_id)
Example
account = Account( connection_id=connection_id, provider_account_id="SCHWAB-12345", account_number_masked="**1234", name="Individual Brokerage", account_type="brokerage", balance=Decimal("10000.00"), currency="USD", ) session.add(account) await session.commit()
Source code in src/infrastructure/persistence/models/account.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |