Last active
May 6, 2017 13:00
-
-
Save StaverDmitry/656f3d556d29a578fdc37eaa3dd134eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Passenger.find_in_batches batch_size: 1000 do |passengers| | |
execute <<-SQL | |
UPDATE passengers AS p | |
SET cruise_index = crs.name, | |
person_index = person.name | |
FROM passengers, enquiries e, tours t, directions d, cruises crs, | |
(SELECT id, name FROM ( | |
SELECT p.id, concat(coalesce(par.first_name, c.first_name), ' ',coalesce(par.last_name, c.last_name)) AS name | |
FROM passengers p | |
LEFT JOIN partners par | |
ON p.partner_id = par.id | |
LEFT JOIN customers c | |
ON c.id = p.customer_id) as t where name <> ' ') as person | |
WHERE p.enquiry_id = e.id | |
AND e.tour_id = t.id | |
AND t.direction_id = d.id | |
AND d.cruise_id = crs.id | |
AND p.id = person.id | |
AND passengers.id in (#{passengers.map(&:id).join ','}) | |
SQL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment