Import Customers First
bin/rails legacy:import_customers
This creates companies with "Legacy ID: XXX" in notes for mapping.
Verify Vendors & Products Exist
bin/rails legacy:test
Shows if you can connect to the legacy MySQL database.
bin/rails legacy:stats
Shows order counts, status breakdown, top vendors, recent orders.
# Preview all orders from last 2 years
bin/rails legacy:preview_order_import
# Preview specific date range
bin/rails legacy:preview_order_import[2024-01-01,2025-12-31]
This shows:
# Test import without saving (default is dry run)
bin/rails legacy:import_orders[2024-01-01,2025-12-31]
# Or explicitly
bin/rails legacy:import_orders[2024-01-01,2025-12-31,true]
Shows exactly what would happen without actually importing.
# CAUTION: This actually imports data!
bin/rails legacy:import_orders[2024-01-01,2025-12-31,false]
bin/rails legacy:uninvoiced_orders_report
Creates a CSV file with all imported orders that need invoicing.
1. Connect to Legacy DB
↓
2. Map Vendors (by name)
↓
3. Map Products (by name)
↓
4. Map Customers (by legacy ID in notes)
↓
5. For Each Order:
- Check if already imported (skip if yes)
- Map status (delivered → active, etc.)
- Map payment method (cc → credit_card, etc.)
- Calculate rental days from dates
- Create company/contact if needed
- Import order with all fields
- Track with legacy_order_id
↓
6. Generate Summary Report
legacy_order_id - Original order IDimported_at - When importedimport_notes - Import details (original product name, vendor, PO#)# In Rails console
bin/rails console
# See all imported orders
Order.where.not(legacy_order_id: nil).count
# See uninvoiced imported orders
Order.where.not(legacy_order_id: nil).where(invoice_id: nil).count
# Find a specific legacy order
Order.find_by(legacy_order_id: 12345)
Run uninvoiced report:
bin/rails legacy:uninvoiced_orders_report
Review the CSV file
Use the billing run system to create invoices:
If something goes wrong:
# In Rails console
bin/rails console
# Delete ALL imported orders
Order.where.not(legacy_order_id: nil).delete_all
# Delete orders imported after a certain time
Order.where.not(legacy_order_id: nil)
.where("imported_at > ?", 1.hour.ago)
.delete_all
# Then re-run import with corrections
import_notes field to see original vendor/product nameslegacy:import_customers firstlegacy_order_id are skippedStart Small
Always Use Dry Run First
bin/rails legacy:import_orders[2024-01-01,2024-03-31]
# Review output, then:
bin/rails legacy:import_orders[2024-01-01,2024-03-31,false]
Import in Batches
Focus on Uninvoiced First
Verify After Import
| Legacy | New | Invoiceable? |
|---|---|---|
| pending | pending | No |
| confirmed | confirmed | No |
| delivered | active | No |
| active | active | Yes |
| completed | completed | Yes |
| cancelled | cancelled | No |
| Legacy | New |
|---|---|
| cc, credit_card | credit_card |
| po, purchase_order | purchase_order |
| cash | purchase_order |
| check | purchase_order |
For issues or questions:
# 1. Test connection
bin/rails legacy:test
# 2. Import customers (if not done)
bin/rails legacy:import_customers
# 3. Preview what would be imported
bin/rails legacy:preview_order_import[2024-01-01,2024-12-31]
# 4. Dry run to see details
bin/rails legacy:import_orders[2024-01-01,2024-12-31]
# 5. Review output, then actually import
bin/rails legacy:import_orders[2024-01-01,2024-12-31,false]
# 6. Generate uninvoiced report
bin/rails legacy:uninvoiced_orders_report
# 7. Open the CSV and review
# 8. Create invoices via billing runs in admin UI