Your next dashboard refresh can turn a customer into a sourcing lead.
You're merging importer and supplier profiles into a relationship table. Treating every profile owner as the buyer looks convenient. It also puts the mistake somewhere nobody enjoys debugging: inside otherwise valid rows.
For a US importer, partners contains suppliers; for a supplier, it contains customers. Flattening that field with a fixed owner-to-supplier rule reverses supplier-profile relationships.
The repair starts before the upsert. Preserve the profile context, resolve direction explicitly, and keep unidentified partners out of the graph.
Start with a bounded profile job
Use profile mode when you already know the pages you need. Disable shipment rows here because a profile relationship and a bill of lading need different ingestion contracts.
Install apify-client , zod , and pg .…