Files
Rikard BartholfandGitHub ddcbd0afb0 Archive old migrations (#426)
* Archive old migrations

* Fix invalid placement of migrations
2024-10-17 11:19:12 +02:00

78 lines
2.7 KiB
SQL

INSERT INTO printproducts_defaults (print_id, width_mm, height_mm, crop_x, crop_y, border)
SELECT
printid as print_id,
(CASE
WHEN width_height_ratio >= 1.4 THEN 700 -- landscape in landscape
ELSE 500 -- else square in landscape, square in square or square in portrait or portrait in portrait
END) as width_mm,
(CASE
WHEN width_height_ratio <= 0.7142857143 THEN 700 -- portrait in portrait
ELSE 500 -- else square in portrait, square in square, square in landscape or landscape in landscape
END) as height_mm,
(CASE
WHEN width_height_ratio >= 1.4 THEN ( -- landscape in landscape
LEAST(
width - (height * 1.4 / 2), -- max right side
GREATEST(
height * 1.4 / 2, -- max left side = 0
COALESCE("focusXpoint2", 50) / 100 * width -- focuspoint
)
) - (height * 1.4 / 2) -- convert to left edge
) / width -- convert to percent
--------------------
WHEN width_height_ratio > 1 AND width_height_ratio < 1.4 THEN ( -- square in landscape
LEAST(
width - (height / 2), -- max right side
GREATEST(
height / 2, -- max left side = 0
COALESCE("focusXpoint2", 50) / 100 * width -- focuspoint
)
) - (height / 2) -- convert to left edge
) / width -- convert to percent
--------------------
WHEN width_height_ratio < 1 AND width_height_ratio > 0.7142857143 THEN 0 -- square in portrait
--------------------
WHEN width_height_ratio <= 0.7142857143 THEN 0 -- portrait in portrait
--------------------
ELSE 0 -- square in square
END) as crop_x,
(CASE
WHEN width_height_ratio >= 1.4 THEN 0 -- landscape in landscape
--------------------
WHEN width_height_ratio > 1 AND width_height_ratio < 1.4 THEN 0 -- square in landscape
--------------------
WHEN width_height_ratio < 1 AND width_height_ratio > 0.7142857143 THEN ( -- square in portrait
LEAST(
height - ((width) / 2), -- max bottom side
GREATEST(
(width) / 2, -- max top side = 0
COALESCE("focusYpoint2", 50) / 100 * height -- focuspoint
)
) - (width) / 2) -- convert to top edge
/ height -- convert to percent
--------------------
WHEN width_height_ratio <= 0.7142857143 THEN ( -- portrait in portrait
LEAST(
height - ((width / 0.7142857143) / 2), -- max bottom side
GREATEST(
(width / 0.7142857143) / 2, -- max top side = 0
COALESCE("focusYpoint2", 50) / 100 * height -- focuspoint
)
) - (width / 0.7142857143) / 2) -- convert to top edge
/ height -- convert to percent
--------------------
ELSE 0 -- square in square
END) as crop_y,
'none' as border
FROM
"product-printproducts" ppp
JOIN v_product vp ON ppp.productid = vp.id
LEFT JOIN printproducts_defaults ppd ON ppd.print_id = ppp.printid
WHERE groupid = 7
AND ppd.print_id IS NULL;