SnapTrade Account Type Migration
Overview
Migrating SnapTrade accounts to use Plaid-styletype + subtype columns for consistent UX across all account sources, while maintaining backward compatibility with existing account_type column.
Strategy: Dual-Column Approach (Zero Breaking Changes)
Database Schema
How It Works
On Account Creation (process-connection/route.ts)
On Account Update (update-type/route.ts)
In UI (accounts/page.tsx)
In Business Logic (account-type-utils.ts)
Files Changed
✅ Already Updated
/lib/account-type-mappings.ts- Added SNAPTRADE_TO_PLAID_MAPPING (CENTRAL SOURCE OF TRUTH)/app/accounts/page.tsx- Dialog now uses type/subtype for SnapTrade/app/api/snaptrade/process-connection/route.ts- Sets all columns on create/app/api/accounts/update-type/route.ts- Updates both old and new columns/sql-queries/add-account-type-override-support.sql- Migration script
⚠️ NOT Changed (Intentionally)
All existing code that readsaccount_type continues to work:
- Display components
- Calculation logic
- Categorization functions
- No breaking changes!
Migration Steps
-
Run SQL Migration
-
Deploy Code Changes
- All files already updated
- No additional code changes needed
-
Existing Accounts Auto-Migrate
- SQL migration populates new columns
- Old
account_typeremains unchanged - Both old and new code paths work
Backward Compatibility
Old Code Reads account_type
✅ Still works! Column is maintained and kept in sync.
New Code Reads type/subtype
✅ Works! New columns are populated.
Gradual Migration Path
- Can slowly update components to use
type/subtypeover time - No rush to change everything at once
account_typecan be deprecated eventually, but not required
Benefits
- Consistent UX - SnapTrade accounts now show same UI as Plaid accounts
- No Breaking Changes - Existing code continues working
- Flexible Migration - Can update code gradually
- User Override Support - Users can change Investment > Depository, etc.
- Subtype Granularity - Users can pick 401k, IRA, Brokerage, etc.
Example
Before
- UI: Single dropdown with “401K”, “IRA”, “ROTH”, “I” (confusing)
- No subtypes: Just raw SnapTrade types
After
- UI: Two dropdowns
- Type: Investment, Depository, Loan, etc.
- Subtype: 401k, IRA, Brokerage, etc.
- Consistent: Same UX as Plaid and Manual accounts
- Backward Compatible: Old
account_typestill populated
Maintaining the Type Mapping
IMPORTANT: The SnapTrade → Plaid type mapping is centralized in ONE place: Source of Truth:/lib/account-type-mappings.ts → SNAPTRADE_TO_PLAID_MAPPING
Used by:
app/api/snaptrade/process-connection/route.ts- Creates new accountsapp/accounts/page.tsx- Initializes edit dialogsql-queries/add-account-type-override-support.sql- Migration backfill (reference only)
- Add it to
SNAPTRADE_TO_PLAID_MAPPINGin/lib/account-type-mappings.ts - Done! All code will automatically use the new mapping
- SQL migration is one-time only - no need to update
Testing Checklist
- Run SQL migration in Supabase
- Edit a SnapTrade account - should see Type/Subtype dropdowns
- Change type from Investment to Depository - should work
- Old calculations still work (check dashboard, net worth, charts)
- New accounts get both old and new columns populated
- User overrides are tracked properly (type != source_type)