import db
query = """
SELECT p.id, p.file_path, COALESCE(o.material_name, 'Showcase') as material_name, p.order_id
FROM order_photos p
LEFT JOIN orders o ON p.order_id = o.id
WHERE p.is_public = TRUE AND (o.id IS NULL OR o.allow_portfolio = TRUE)
ORDER BY p.created_at DESC
"""
res = db.execute_query(query)
print(res)
