Sha256: c5da9a5a84784a65f71ce6fad8596ab24ceb94416c61349f3c5446bca92533d9

Contents?: true

Size: 1021 Bytes

Versions: 23

Compression:

Stored size: 1021 Bytes

Contents

class CreateAbsences < ActiveRecord::Migration
  def self.up
    create_table :absences do |t|
      t.column :user_id, :integer, :null => false, :references => [:users, :party_id]
      t.column :on, :date, :null => false
      t.column :reason, :string, :null => false
    end
    
    add_column :works, :started_on, :date, :null => true
    add_column :works, :start_time, :time, :null => true
    Work.find(:all).each do |w|
      w.started_on = (w.started_at || w.completed_at).to_date
      w.start_time = w.started_at && w.started_at.time_of_day
      w.save!
    end
    change_column_null :works, :started_on, :date, false
    remove_column :works, :started_at
  end
  
  def self.down
    add_column :works, :started_at, :timestamp
    Work.find(:all).each do |w|
      w.started_at = w.start_time && w.start_time.on(w.started_on)
      w.save!
    end
    remove_column :works, :started_on
    remove_column :works, :start_time
    drop_table :absences
  end
  
  class Work < ActiveRecord::Base
  end
  
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
backlog-0.37.2 db/migrate/028_create_absences.rb
backlog-0.37.1 db/migrate/028_create_absences.rb
backlog-0.36.2 db/migrate/028_create_absences.rb
backlog-0.24.0 db/migrate/028_create_absences.rb
backlog-0.25.0 db/migrate/028_create_absences.rb
backlog-0.26.0 db/migrate/028_create_absences.rb
backlog-0.28.0 db/migrate/028_create_absences.rb
backlog-0.29.0 db/migrate/028_create_absences.rb
backlog-0.30.0 db/migrate/028_create_absences.rb
backlog-0.31.0 db/migrate/028_create_absences.rb
backlog-0.32.0 db/migrate/028_create_absences.rb
backlog-0.31.1 db/migrate/028_create_absences.rb
backlog-0.33.0 db/migrate/028_create_absences.rb
backlog-0.33.1 db/migrate/028_create_absences.rb
backlog-0.34.1 db/migrate/028_create_absences.rb
backlog-0.34.2 db/migrate/028_create_absences.rb
backlog-0.34 db/migrate/028_create_absences.rb
backlog-0.35.0 db/migrate/028_create_absences.rb
backlog-0.35.2 db/migrate/028_create_absences.rb
backlog-0.35.1 db/migrate/028_create_absences.rb