fix: correct Product-Constructeur join table orientation

The _ProductConstructeurs table was created with wrong column order:
- Before: A=product, B=constructeur
- After: A=constructeur, B=product (alphabetical order expected by Prisma)

This caused Prisma to fail loading constructeurs relations, resulting in empty constructeurs arrays in API responses.

Changes:
- Added migration to swap A/B columns and recreate foreign keys
- Added debug logs in products.service.ts and constructeur-link.util.ts

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-01-22 11:48:06 +01:00
parent 8cfe48e0f5
commit ff278f5549
3 changed files with 56 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
-- Fix _ProductConstructeurs table orientation
-- Issue: Table was created with A=product, B=constructeur
-- But Prisma expects alphabetical order: A=constructeur, B=product
-- Step 1: Save existing data to temp table
CREATE TEMP TABLE _ProductConstructeurs_backup AS
SELECT "A" as old_A, "B" as old_B FROM "_ProductConstructeurs";
-- Step 2: Drop foreign key constraints
ALTER TABLE "_ProductConstructeurs" DROP CONSTRAINT IF EXISTS "_ProductConstructeurs_A_fkey";
ALTER TABLE "_ProductConstructeurs" DROP CONSTRAINT IF EXISTS "_ProductConstructeurs_B_fkey";
-- Step 3: Clear the table
TRUNCATE TABLE "_ProductConstructeurs";
-- Step 4: Reinsert data with swapped columns (A and B inverted)
INSERT INTO "_ProductConstructeurs" ("A", "B")
SELECT old_B, old_A FROM _ProductConstructeurs_backup;
-- Step 5: Recreate foreign key constraints with correct orientation
ALTER TABLE "_ProductConstructeurs"
ADD CONSTRAINT "_ProductConstructeurs_A_fkey"
FOREIGN KEY ("A") REFERENCES "constructeurs"("id")
ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "_ProductConstructeurs"
ADD CONSTRAINT "_ProductConstructeurs_B_fkey"
FOREIGN KEY ("B") REFERENCES "products"("id")
ON DELETE CASCADE ON UPDATE CASCADE;