Fix for room swap migration
This commit is contained in:
+12
-7
@@ -15359,7 +15359,7 @@ BEGIN
|
|||||||
FROM temp_room_updates tru
|
FROM temp_room_updates tru
|
||||||
LEFT JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
LEFT JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
||||||
WHERE pp.printid IS NULL;
|
WHERE pp.printid IS NULL;
|
||||||
|
|
||||||
IF missing_count > 0 THEN
|
IF missing_count > 0 THEN
|
||||||
RAISE NOTICE 'Warning: % products have no matching prints with groupid 1 or 3', missing_count;
|
RAISE NOTICE 'Warning: % products have no matching prints with groupid 1 or 3', missing_count;
|
||||||
END IF;
|
END IF;
|
||||||
@@ -15374,7 +15374,7 @@ BEGIN
|
|||||||
FROM temp_room_updates tru
|
FROM temp_room_updates tru
|
||||||
LEFT JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing'
|
LEFT JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing'
|
||||||
WHERE r.id IS NULL;
|
WHERE r.id IS NULL;
|
||||||
|
|
||||||
IF invalid_count > 0 THEN
|
IF invalid_count > 0 THEN
|
||||||
RAISE NOTICE 'Warning: % unique room names not found in database', invalid_count;
|
RAISE NOTICE 'Warning: % unique room names not found in database', invalid_count;
|
||||||
END IF;
|
END IF;
|
||||||
@@ -15391,18 +15391,18 @@ BEGIN
|
|||||||
FROM temp_room_updates tru
|
FROM temp_room_updates tru
|
||||||
INNER JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
INNER JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
||||||
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing';
|
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing';
|
||||||
|
|
||||||
SELECT COUNT(pp.printid) INTO print_count
|
SELECT COUNT(pp.printid) INTO print_count
|
||||||
FROM temp_room_updates tru
|
FROM temp_room_updates tru
|
||||||
INNER JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
INNER JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
||||||
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing';
|
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing';
|
||||||
|
|
||||||
SELECT COUNT(*) INTO interior_count
|
SELECT COUNT(*) INTO interior_count
|
||||||
FROM temp_room_updates tru
|
FROM temp_room_updates tru
|
||||||
INNER JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
INNER JOIN "product-printproducts" pp ON pp.productid = tru.product_id AND pp.groupid IN (1, 3)
|
||||||
INNER JOIN interiors i ON i.print_id = pp.printid AND i.position = 0
|
INNER JOIN interiors i ON i.print_id = pp.printid AND i.position = 0
|
||||||
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing';
|
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing';
|
||||||
|
|
||||||
RAISE NOTICE 'Summary: % products, % prints matched. Currently % interiors exist at position 0 (will be updated, rest will be inserted)', product_count, print_count, interior_count;
|
RAISE NOTICE 'Summary: % products, % prints matched. Currently % interiors exist at position 0 (will be updated, rest will be inserted)', product_count, print_count, interior_count;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
@@ -15419,7 +15419,12 @@ UPDATE interiors i
|
|||||||
SET room_id = prm.new_room_id
|
SET room_id = prm.new_room_id
|
||||||
FROM print_room_mapping prm
|
FROM print_room_mapping prm
|
||||||
WHERE i.print_id = prm.printid
|
WHERE i.print_id = prm.printid
|
||||||
AND i.position = 0;
|
AND i.position = 0
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM interiors i2
|
||||||
|
WHERE i2.print_id = i.print_id
|
||||||
|
AND i2.room_id = prm.new_room_id
|
||||||
|
);
|
||||||
|
|
||||||
-- Step 5: Insert new position 0 interiors for prints that don't have them yet
|
-- Step 5: Insert new position 0 interiors for prints that don't have them yet
|
||||||
WITH print_room_mapping AS (
|
WITH print_room_mapping AS (
|
||||||
@@ -15450,7 +15455,7 @@ BEGIN
|
|||||||
INNER JOIN interiors i ON i.print_id = pp.printid AND i.position = 0
|
INNER JOIN interiors i ON i.print_id = pp.printid AND i.position = 0
|
||||||
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing'
|
INNER JOIN rooms r ON r.name = tru.new_room_name || '_wallpaper_standing'
|
||||||
WHERE i.room_id = r.id;
|
WHERE i.room_id = r.id;
|
||||||
|
|
||||||
RAISE NOTICE 'Verification: Successfully updated/inserted % position 0 interiors with correct room_id', updated_count;
|
RAISE NOTICE 'Verification: Successfully updated/inserted % position 0 interiors with correct room_id', updated_count;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user