infrastructure.persistence.models.provider_connection¶
src.infrastructure.persistence.models.provider_connection
¶
Provider connection database model.
This module defines the ProviderConnection model for storing user-provider connection data including encrypted credentials.
Security
- encrypted_credentials: AES-256 encrypted credential blob
- credentials_expires_at: Token expiration for proactive refresh
- Domain never sees raw credentials (infrastructure handles encryption)
Reference
- docs/architecture/provider-domain-model.md
- docs/architecture/repository-pattern.md
Classes¶
ProviderConnection
¶
Bases: BaseMutableModel
Provider connection model for user-provider relationships.
Stores the connection between a user and a financial data provider, including encrypted OAuth credentials and connection state.
Fields
id: UUID primary key (from BaseMutableModel) created_at: Timestamp when connection was created (from BaseMutableModel) updated_at: Timestamp when connection was last updated (from BaseMutableModel) user_id: FK to users table (cascade delete) provider_id: UUID for future providers table (no FK constraint yet) provider_slug: Denormalized provider identifier (e.g., "schwab") status: Connection lifecycle state (pending, active, expired, etc.) alias: User-defined nickname for the connection credential_type: Type of credential (oauth2, api_key, etc.) encrypted_credentials: AES-256 encrypted credential blob credentials_expires_at: When credentials expire connected_at: When connection was first established last_sync_at: Last successful data synchronization
Indexes
- idx_provider_connections_user_id: (user_id) for user queries
- idx_provider_connections_user_provider: (user_id, provider_id) for unique lookups
- idx_provider_connections_status: (status) for filtering active connections
- idx_provider_connections_expires: (credentials_expires_at) for refresh jobs
Example
conn = ProviderConnection( user_id=user_id, provider_id=provider_id, provider_slug="schwab", status="pending", ) session.add(conn) await session.commit()
Source code in src/infrastructure/persistence/models/provider_connection.py
25 26 27 28 29 30 31 32 33 34 35 36 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 | |