Sha256: 05f68824307afc1694712f7346d109555ec2c66b3f2874647a0f2fda2610fd36

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

class CreateEstimates < ActiveRecord::Migration
  def self.up
    create_table :estimates do |t|
      t.column "task_id",      :integer,                                                 :null => false
      t.column "todo",         :decimal,  :precision => 6, :scale => 2, :default => 1.0, :null => false
      t.column "created_at", :datetime,                                                :null => false
    end

    execute "INSERT INTO estimates(task_id, todo, created_at) SELECT task_id, todo, completed_at FROM works"
    
    remove_column :works, :todo
  end

  def self.down
    add_column :works, "todo", :decimal,  :precision => 6, :scale => 2, :default => 1.0, :null => true
    execute("UPDATE works SET todo = (SELECT todo FROM estimates e1 WHERE e1.task_id = works.task_id AND e1.created_at <= works.completed_at AND NOT EXISTS (SELECT completed_at FROM estimates e2 where e2.task_id = works.task_id AND e2.created_at <= works.completed_at AND e2.created_at > e1.created_at))")
    change_column :works, "todo", :decimal,  :precision => 6, :scale => 2, :default => 1.0, :null => false
    drop_table :estimates
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
backlog-0.0.0 db/migrate/013_create_estimates.rb
backlog-0.0.1 db/migrate/013_create_estimates.rb
backlog-0.0.2 db/migrate/013_create_estimates.rb
backlog-0.0.4 db/migrate/013_create_estimates.rb