YaleSTC / shifts

Application to easily track shifts, reports, and payforms for employees.
MIT License
23 stars 18 forks source link

Make_future methods for Shifts and TimeSlots fail on some machines #446

Closed njlxyaoxinwei closed 9 years ago

njlxyaoxinwei commented 9 years ago

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

mnquintana commented 9 years ago

Are you sure it's a Mac thing and not a version-specific thing?

njlxyaoxinwei commented 9 years ago

@mnquintana Somehow this happened on both Macs that I tried to set up Shifts on. No Linux distros had any problems...

mnquintana commented 9 years ago

Hmmm with the same version number?

jasonkliu commented 9 years ago

https://github.com/YaleSTC/shifts/blob/fd3c348f8e9e39ae9ffdfb263e371817803365cb/app/models/time_slot.rb#L35

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
njlxyaoxinwei commented 9 years ago

We can use Arel to better generate SQL queries for conflict, and use ActiveRecordImport gem to insert TimeSlots records

jasonkliu commented 9 years ago

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])
njlxyaoxinwei commented 9 years ago

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.

njlxyaoxinwei commented 9 years ago

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.