Sha256: 04493e14581c6e51c5d58c0b303b16fb34dd0f7df1c963c9f5e103960683477c

Contents?: true

Size: 1.13 KB

Versions: 119

Compression:

Stored size: 1.13 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 > e1.created_at OR (e2.id > e1.id 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

119 entries across 119 versions & 1 rubygems

Version Path
backlog-0.37.2 db/migrate/013_create_estimates.rb
backlog-0.37.1 db/migrate/013_create_estimates.rb
backlog-0.36.2 db/migrate/013_create_estimates.rb
backlog-0.0.5 db/migrate/013_create_estimates.rb
backlog-0.1.1 db/migrate/013_create_estimates.rb
backlog-0.1.0 db/migrate/013_create_estimates.rb
backlog-0.1.2 db/migrate/013_create_estimates.rb
backlog-0.10.1 db/migrate/013_create_estimates.rb
backlog-0.10.0 db/migrate/013_create_estimates.rb
backlog-0.10.3 db/migrate/013_create_estimates.rb
backlog-0.10.4 db/migrate/013_create_estimates.rb
backlog-0.10.5 db/migrate/013_create_estimates.rb
backlog-0.10.2 db/migrate/013_create_estimates.rb
backlog-0.10.7 db/migrate/013_create_estimates.rb
backlog-0.10.6 db/migrate/013_create_estimates.rb
backlog-0.10.8 db/migrate/013_create_estimates.rb
backlog-0.11.0 db/migrate/013_create_estimates.rb
backlog-0.12.0 db/migrate/013_create_estimates.rb
backlog-0.12.2 db/migrate/013_create_estimates.rb
backlog-0.12.1 db/migrate/013_create_estimates.rb