Legacy Order Import Strategy

Overview

This document outlines the strategy for importing historical orders from the legacy system into the new Rails application.

Current System Mapping

Legacy Order Fields → New Order Fields

Legacy Field New Field Notes
order_id order_number Keep original ID for reference
status status Map statuses (see below)
customer_id company_id/contact_id Lookup migrated customer
firstname/lastname contact Create/lookup contact
vendor_id vendor_id Match by legacy vendor mapping
product/product_id product_id Match by name or create mapping
dropofftime delivery_date Convert timestamp to date
pickuptime pickup_date Calculate rental_days
address/city/state/zip delivery_address, etc Direct mapping
notes notes Customer-visible notes
vendor_dropoff_notes internal_notes Vendor instructions
price base_price Rental price
cost vendor_base_cost Vendor cost
total_amount total_amount Total after tax
paymentmethod payment_method Map payment methods
ponum payment_terms note PO number reference
billing* fields billing_* fields Billing address info

Status Mapping

Legacy Status New Status Invoice?
pending pending No
confirmed confirmed No
delivered active No
active active No
completed completed Yes
cancelled cancelled No

Payment Method Mapping

Legacy New Notes
cc, credit_card credit_card
po, purchase_order purchase_order
cash purchase_order Convert to PO with notes
check purchase_order Convert to PO with notes

Import Process

Phase 1: Pre-Import Validation

  1. Verify all vendors exist in new system
  2. Create vendor mapping table (legacy_id → new_id)
  3. Create product mapping table
  4. Verify customers have been imported
  5. Generate import report showing:

Phase 2: Test Import (Dry Run)

  1. Import 10-20 sample orders
  2. Validate data integrity
  3. Check calculations (totals, dates)
  4. Verify vendor/customer relationships
  5. Review unmapped fields

Phase 3: Batch Import

  1. Import orders in batches of 100
  2. Skip orders with errors (log for review)
  3. Track progress with counters
  4. Generate detailed log file

Phase 4: Post-Import Tasks

  1. Generate uninvoiced orders report
  2. Review orders needing attention
  3. Create invoices for completed orders
  4. Reconcile totals with legacy system

Import Options

Option 1: Import All Historical Data

Option 2: Import Only Uninvoiced Orders

Option 3: Import Active + Uninvoiced

Data Mapping Tables

We'll create these reference tables to maintain mappings:

# In new system - track legacy mappings
Order.add_columns:
  - legacy_order_id (integer)
  - imported_at (datetime)
  - import_notes (text)

# Vendor mapping (in import task)
@vendor_mapping = {
  legacy_vendor_id => new_vendor_id,
  # Populated during import
}

# Product mapping (by name matching)
@product_mapping = {
  "20 Yard Dumpster" => Product.find_by(name: "20 Yard Dumpster")&.id,
  # Etc.
}

Handling Edge Cases

Missing Vendors

Missing Products

Invalid Addresses

Payment Data

Invoice Generation Strategy

After import, for uninvoiced orders:

  1. Group by Customer + Time Period

  2. Review Before Invoicing

  3. Generate Drafts First

Running the Import

# Test connection
bin/rails legacy:test

# View statistics
bin/rails legacy:stats

# Import customers first (if not done)
bin/rails legacy:import_customers

# Preview order import
bin/rails legacy:preview_order_import[2024-01-01,2025-12-31]

# Import orders (dry run)
bin/rails legacy:import_orders[2024-01-01,2025-12-31,true]

# Actual import
bin/rails legacy:import_orders[2024-01-01,2025-12-31,false]

# Generate uninvoiced report
bin/rails legacy:uninvoiced_orders_report

Success Metrics

Rollback Plan

If import fails or has issues:

  1. All imported orders have legacy_order_id field
  2. Can delete with: Order.where.not(legacy_order_id: nil).delete_all
  3. Re-run import with fixes
  4. Incremental import possible (skip existing)