- Changed encoding fallback order to prioritize iso-8859-1/latin-1 over cp1252 - Increased encoding test from 1KB to 10KB to catch issues deeper in files - Added proper file handle cleanup on encoding failures - Resolves 'charmap codec can't decode byte 0x9d' error in rolodex import - Tested with rolodex file containing 52,100 rows successfully
9.8 KiB
CSV Import System - User Guide
Overview
The CSV import system allows you to migrate legacy Paradox database data into the Delphi Database application. The system works in two stages:
- Import Stage: Load CSV files into legacy database models (preserving original schema)
- Sync Stage: Synchronize legacy data to modern simplified models
Prerequisites
- Admin access to the application
- CSV files from the legacy Paradox database
- Docker container running
Import Order
IMPORTANT: Import tables in this exact order to avoid foreign key errors:
Stage 1: Reference Tables (Import First)
These tables contain lookup data used by other tables.
- TRNSTYPE.csv - Transaction types
- TRNSLKUP.csv - Transaction lookup
- FOOTERS.csv - Footer templates
- FILESTAT.csv - File status codes
- EMPLOYEE.csv - Employee records
- GRUPLKUP.csv - Group lookup
- FILETYPE.csv - File type codes
- FVARLKUP.csv - File variable lookup
- RVARLKUP.csv - Rolodex variable lookup
Stage 2: Core Data Tables
- ROLODEX.csv - Client/contact information
- PHONE.csv - Phone numbers (references ROLODEX)
- ROLEX_V.csv - Rolodex variables (references ROLODEX)
- FILES.csv - Case/file records (references ROLODEX)
- FILES_R.csv - File relationships (references FILES)
- FILES_V.csv - File variables (references FILES)
- FILENOTS.csv - File notes/memos (references FILES)
- LEDGER.csv - Transaction ledger (references FILES)
- DEPOSITS.csv - Deposit records
- PAYMENTS.csv - Payment records (references FILES)
Stage 3: Specialized Tables
- PLANINFO.csv - Pension plan information
- QDROS.csv - QDRO documents (references FILES)
- PENSIONS.csv - Pension records (references FILES)
- Pensions/MARRIAGE.csv - Marriage calculations (references PENSIONS)
- Pensions/DEATH.csv - Death benefit calculations (references PENSIONS)
- Pensions/SCHEDULE.csv - Vesting schedules (references PENSIONS)
- Pensions/SEPARATE.csv - Separation calculations (references PENSIONS)
- Pensions/RESULTS.csv - Pension calculation results (references PENSIONS)
Step-by-Step Import Process
1. Access Admin Panel
- Navigate to
http://localhost:8000/admin - Login with admin credentials (default: admin/admin)
2. Upload CSV Files
- Scroll to the File Upload section
- Click "Select CSV Files" and choose your CSV files
- You can upload multiple files at once
- Choose whether to enable "Auto-import after upload" (default ON). When enabled, the system will import the uploaded files immediately following the Import Order Guide and will stop after the first file that reports any row errors.
- Click "Upload Files"
- Review the upload and auto-import results to ensure files were recognized and processed correctly
3. Import Reference Tables First
- Scroll to the Data Import section
- You'll see files grouped by type (trnstype, trnslkup, footers, etc.)
- For each reference table group:
- Select the checkbox next to the file(s) you want to import
- Click the "Import" button for that group
- Wait for the import to complete
- Review the results
Tip: Use the "Select All" button to quickly select all files in a group.
4. Import Core Data Tables
Following the same process as step 3, import the core tables in order:
- Import rolodex files
- Import phone files
- Import rolex_v files
- Import files files
- Import files_r files
- Import files_v files
- Import filenots files
- Import ledger files
- Import deposits files
- Import payments files
5. Import Specialized Tables
Finally, import the specialized tables:
- Import planinfo files
- Import qdros files
- Import pensions files
- Import pension_marriage files
- Import pension_death files
- Import pension_schedule files
- Import pension_separate files
- Import pension_results files
6. Sync to Modern Models
After all legacy data is imported:
- Scroll to the Sync to Modern Models section
- OPTIONAL: Check "Clear existing modern data before sync" if you want to replace all current data
- ⚠️ WARNING: This will delete all existing Client, Phone, Case, Transaction, Payment, and Document records!
- Click "Start Sync Process"
- Confirm the action in the dialog
- Review the sync results
The sync process will:
- Convert Rolodex → Client
- Convert LegacyPhone → Phone
- Convert LegacyFile → Case
- Convert Ledger → Transaction
- Convert LegacyPayment → Payment
- Convert Qdros → Document
Monitoring Import Progress
Import Results
After each import operation, you'll see:
- Total Rows: Number of rows in the CSV file
- Success Count: Records successfully imported
- Error Count: Records that failed to import
- Detailed Errors: Specific error messages for failed records (first 10 shown)
Import History
The Recent Import History section shows the last 10 import operations with:
- Import type
- Filename
- Status (Completed/Failed/Running)
- Record counts
- Timestamp
Sync Results
After syncing, you'll see:
- Records Synced: Total records successfully synced to modern models
- Records Skipped: Records that couldn't be synced (e.g., missing foreign keys)
- Errors: Count of errors encountered
- Per-Table Details: Breakdown showing results for each modern table (Client, Phone, Case, etc.)
Troubleshooting
Import Errors
"Foreign key constraint failed"
- You imported tables out of order
- Solution: Import reference tables first, then core tables
"No client found for rolodex ID"
- The ROLODEX file wasn't imported before dependent files
- Solution: Import ROLODEX.csv first
"No case found for file"
- The FILES file wasn't imported before LEDGER/PAYMENTS
- Solution: Import FILES.csv before LEDGER.csv and PAYMENTS.csv
"Encoding error" or "Unable to open file"
- CSV file has unusual encoding
- The system tries multiple encodings automatically
- Check the error message for details
Sync Errors
"Records Skipped"
- Legacy records reference non-existent parent records
- This is normal for incomplete datasets
- Review skipped record details in the sync results
"Duplicate key error"
- Running sync multiple times without clearing existing data
- Solution: Check "Clear existing modern data before sync" option
Data Validation
After importing and syncing, verify your data:
Check Record Counts
- Navigate to the Dashboard (
/) - Review the statistics cards showing counts for:
- Total Clients
- Active Cases
- Total Transactions
- Recent Payments
Verify Relationships
- Go to the Rolodex page (
/rolodex) - Click on a client
- Verify that:
- Phone numbers are displayed correctly
- Associated cases are shown
- Case details link to transactions and payments
Run Reports
Test the reporting functionality:
- Generate a Phone Book report
- Generate a Payments report
- Verify data appears correctly in PDFs
Best Practices
- Backup First: Always backup your database before importing
- Test with Sample Data: Test the import process with a small subset of data first
- Import Order Matters: Always follow the recommended import order
- Review Errors: Check import results carefully and address errors before proceeding
- Sync Last: Only run the sync process after all legacy data is successfully imported
- Monitor Progress: For large imports, monitor the Import History section
- Document Issues: Keep notes of any import errors for troubleshooting
File Naming Conventions
The system recognizes files by their names. Supported patterns:
ROLODEX*.csv→ rolodex import typePHONE*.csv→ phone import typeFILES*.csv→ files import typeLEDGER*.csv→ ledger import typePAYMENTS*.csv→ payments import typeTRNSTYPE*.csv→ trnstype import type- etc.
Performance Notes
- Batch Processing: Imports process 500 records per batch for optimal performance
- Large Files: Files with 10,000+ records may take several minutes
- Database Locks: Only one import operation should run at a time
- Memory Usage: Very large files (100,000+ records) may require increased Docker memory allocation
Getting Help
If you encounter issues:
- Check the application logs:
docker-compose logs delphi-db - Review the Import History for error details
- Verify your CSV file format matches the expected schema
- Consult the legacy schema documentation in
docs/legacy-schema.md
Example: Complete Import Sequence
# 1. Start the application
docker-compose up -d
# 2. Access admin panel
# Navigate to http://localhost:8000/admin
# 3. Upload all CSV files at once
# Use the file upload form to select all CSV files
# 4. Import in order:
# - Reference tables (TRNSTYPE, TRNSLKUP, FOOTERS, etc.)
# - Core data (ROLODEX, PHONE, FILES, LEDGER, etc.)
# - Specialized (PLANINFO, QDROS, PENSIONS, etc.)
# 5. Sync to modern models
# Click "Start Sync Process" with or without clearing existing data
# 6. Verify
# Navigate to dashboard and verify record counts
Technical Details
Import Module: app/import_legacy.py
Contains import functions for all legacy tables with:
- Encoding detection (UTF-8, CP1252, Latin-1, etc.)
- Date parsing (MM/DD/YYYY, MM/DD/YY, YYYY-MM-DD)
- Decimal conversion with proper precision
- Batch insert optimization
- Structured logging
Sync Module: app/sync_legacy_to_modern.py
Contains sync functions that:
- Map legacy IDs to modern table IDs
- Handle missing foreign key references gracefully
- Skip orphaned records with warnings
- Maintain referential integrity
- Support incremental or full replacement sync
Database Models
- Legacy Models: Preserve original Paradox schema (Rolodex, LegacyPhone, LegacyFile, Ledger, etc.)
- Modern Models: Simplified application schema (Client, Phone, Case, Transaction, Payment, Document)