Helpful-Queries
List of venue typologies
Venue::TYPOLOGIES
Count venues per typology
Venue.where(typology: 'hairdresser').group(:area).order('COUNT(*) DESC').pluck(:area, 'COUNT(*)')
Venue.where(typology: 'aestethic_depilation').group(:area).order('COUNT(*) DESC').pluck(:area, 'COUNT(*)')
Venue.where(typology: 'spa_massages').group(:area).order('COUNT(*) DESC').pluck(:area, 'COUNT(*)')
Venues without area
Venue.where("area = ''").pluck(:id)
Venues without latitude (or longitude)
Venue.where(latitude: nil).pluck(:id)
Align treatment category of venue_treatments with those of their parent treatments
We don't wanto to use pure SQL query to trigger touch of ResourceUpdate records
VenueTreatment.where('"venue_treatments"."treatment_category_id" != "treatments"."treatment_category_id"').each { |vt| vt.update(treatment_category_id: vt.treatment.treatment_category_id) }
Remove special chars from fields
Clean phone field
UPDATE customers
SET phone = REPLACE(phone, 'à', '')
WHERE phone LIKE '%à%'
AND venue_id = 1212
Move imported customers
customers_ids = Customer.unscoped.where(venue_id: venue_id).where("DATE(created_at) = 'date'").limit(2000).pluck(:id); nil
Customer.unscoped.where(venue_id: venue_id, id: customers_ids).update_all("created_at = created_at - interval 'N days', updated_at = updated_at")