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