In order to make it easier to discover which invoices are related to an order, and to manage these relationships, we need to make a few changes to the order-invoice-relationships table.
- Add a unique constraint on (purchaseOrderId, invoiceId)
- Add alias/table alias to help with cross-index subqueries
- changes above are made
- data migration scripts ensure uniqueness, removing records as needed
- unit tests are updated