* migrations for the roomtypes * rename files * updated types * Added new tabel interiors_roomtypes * remove old migrations * fixed bug * correct numbers
41 lines
1.5 KiB
SQL
41 lines
1.5 KiB
SQL
-- Add interiors id to v_interior_image_urls
|
|
|
|
CREATE OR REPLACE VIEW v_interior_image_urls AS
|
|
SELECT
|
|
interiors.id interior_id,
|
|
"product-printproducts".productid,
|
|
interiors.print_id,
|
|
"product-printproducts".groupid AS product_group,
|
|
rooms.id AS room_id,
|
|
rooms.name AS room_name,
|
|
interiors.position,
|
|
room_types.name AS room_type,
|
|
CASE
|
|
WHEN interiors.room_id IS null THEN
|
|
'/interior-images/' || interiors.id || '.jpg'
|
|
ELSE
|
|
'/interiors/' || "product-printproducts".productid || '/' || rooms.s3_suffix
|
|
END as uri,
|
|
array_agg(DISTINCT roomtypes.name) FILTER (WHERE roomtypes.admin_specific = false) AS room_types
|
|
FROM interiors
|
|
JOIN "product-printproducts" ON "product-printproducts".printid = interiors.print_id
|
|
JOIN "product-groups" ON "product-groups".groupid = "product-printproducts".groupid
|
|
LEFT JOIN rooms ON interiors.room_id = rooms.id
|
|
LEFT JOIN room_types ON room_types.id = rooms.room_type_id
|
|
LEFT JOIN room_roomtypes ON room_roomtypes.room_id = rooms.id
|
|
LEFT JOIN interiors_roomtypes ON interiors_roomtypes.interior_id = interiors.id
|
|
LEFT JOIN roomtypes ON roomtypes.id = CASE
|
|
WHEN interiors.room_id IS NULL THEN interiors_roomtypes.roomtype_id
|
|
ELSE room_roomtypes.roomtype_id
|
|
END
|
|
GROUP BY
|
|
interiors.id,
|
|
"product-printproducts".productid,
|
|
interiors.print_id,
|
|
"product-printproducts".groupid,
|
|
rooms.id,
|
|
rooms.name,
|
|
interiors.position,
|
|
room_types.name,
|
|
rooms.s3_suffix;
|