diff --git a/README.md b/README.md index 3a329f0..3a0a72d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ and use the credentials inside for the migration. To avoid having to enter password for selected user on each run, just use a [.pgpass](http://www.postgresql.org/docs/9.3/static/libpq-pgpass.html) file. +An example .pgpass file can be found in lastpass with name `pgpass`. + +Login information for production cluster can be found is lastpass named `production-cluster - Aurora`. `db-upgrade` assumes the `default` environment should be used if it's argument is omitted. So, start by creating an initial `default.conf` with credentials for your localhost or some non-critical environment. diff --git a/migrations/000.346.sql b/migrations/000.346.sql new file mode 100644 index 0000000..fdb2c74 --- /dev/null +++ b/migrations/000.346.sql @@ -0,0 +1,77 @@ +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;