Closed njlxyaoxinwei closed 9 years ago
Are you sure it's a Mac thing and not a version-specific thing?
@mnquintana Somehow this happened on both Macs that I tried to set up Shifts on. No Linux distros had any problems...
Hmmm with the same version number?
OS X 10.9.5, installed from Homebrew
$ mysql --version
mysql Ver 14.14 Distrib 5.6.23, for osx10.9 (x86_64) using EditLine wrapper
We can use Arel to better generate SQL queries for conflict, and use ActiveRecordImport gem to insert TimeSlots records
Method to output days by index number:
Input: Start Date (2015-01-12), End Date (2015-02-26), Days of Week array [1, 3, 5]
Note that Date.commercial(2015, 3, 1)
gives the 3rd week of 2015...
Use .to_date
to ensure ActiveSupport::TimeWithZone
(actually a Time) converts to a Date.
require 'date'
def week_dates(start_date, end_date, table )
# puts start_date
# puts end_date
# puts table
array = Array.new
(start_date..end_date).each do |i|
# puts i.wday
array << i if table.include? i.wday
end
puts array
end
week_dates(Date.commercial(2015, 3, 1).to_date, Date.today.to_date, [1, 3, 5])
The problem occurs on the following version (probably has to do with OS X version):
mysql Ver 14.14 Distrib 5.6.22, for osx10.10 (x86_64) using EditLine wrapper
But the new make_future for time_slots works on the said machine.
It turns out mysql does freak out about long conditions. Even though the Arel Table can handle the length, when passed to the where method, the program will crash. I will still process these cases in batches then.
For some reason the SQL generated in these two methods aren't recognized by some mysql on Mac OS X. Maybe this is a version specific thing but these two methods are very poorly written too so we should rewrite these two with Rails ActiveRecord