# Controls whether we store device 'active' flag in attributes (default) or telemetry.
# If you device to change this parameter, you should re-create the device info view as one of the following:
# If 'persistToTelemetry' is changed from 'false' to 'true': 'CREATE OR REPLACE VIEW device_info_view AS SELECT * FROM device_info_active_ts_view;'
# If 'persistToTelemetry' is changed from 'true' to 'false': 'CREATE OR REPLACE VIEW device_info_view AS SELECT * FROM device_info_active_attribute_view;'
"AND (:customerId IS NULL OR d.customerId = uuid(:customerId)) "+
"AND (:edgeId IS NULL OR d.id IN (SELECT re.toId FROM RelationEntity re WHERE re.toType = 'DEVICE' AND re.relationTypeGroup = 'EDGE' AND re.relationType = 'Contains' AND re.fromType = 'EDGE' AND re.fromId = uuid(:edgeId))) "+
"AND ((:deviceType) IS NULL OR d.type = :deviceType) "+
"AND (:deviceProfileId IS NULL OR d.deviceProfileId = uuid(:deviceProfileId)) "+
"AND ((:filterByActive) IS FALSE OR (((:persistToTelemetry) IS TRUE AND d.tsActive = :deviceActive) OR ((:persistToTelemetry) IS FALSE AND d.attributeActive = :deviceActive))) "+
"AND ((:filterByActive) IS FALSE OR d.active = :deviceActive) "+
"AND (LOWER(d.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%')) "+
"OR LOWER(d.label) LIKE LOWER(CONCAT('%', :textSearch, '%')) "+
"OR LOWER(d.type) LIKE LOWER(CONCAT('%', :textSearch, '%')) "+
"OR LOWER(d.customerTitle) LIKE LOWER(CONCAT('%', :textSearch, '%')))")