1 class PipelineInstanceState < ActiveRecord::Migration
2 include CurrentApiClient
5 add_column :pipeline_instances, :state, :string
6 add_column :pipeline_instances, :components_summary, :text
8 PipelineInstance.reset_column_information
11 PipelineInstance.all.each do |pi|
12 pi.state = PipelineInstance::New
14 if !pi.attribute_present? :success # success is nil
15 if pi[:active] == true
16 pi.state = PipelineInstance::RunningOnServer
18 if pi.components_look_ready?
19 pi.state = PipelineInstance::Ready
21 pi.state = PipelineInstance::New
24 elsif pi[:success] == true
25 pi.state = PipelineInstance::Complete
27 pi.state = PipelineInstance::Failed
34 # We want to perform addition of state, and removal of active and success in two phases. Hence comment these statements out.
36 if column_exists?(:pipeline_instances, :active)
37 remove_column :pipeline_instances, :active
40 if column_exists?(:pipeline_instances, :success)
41 remove_column :pipeline_instances, :success
47 # We want to perform addition of state, and removal of active and success in two phases. Hence comment these statements out.
49 add_column :pipeline_instances, :success, :boolean, :null => true
50 add_column :pipeline_instances, :active, :boolean, :default => false
53 PipelineInstance.all.each do |pi|
55 when PipelineInstance::New, PipelineInstance::Ready
58 when PipelineInstance::RunningOnServer
61 when PipelineInstance::RunningOnClient
64 when PipelineInstance::Failed
67 when PipelineInstance::Complete
76 if column_exists?(:pipeline_instances, :components_summary)
77 remove_column :pipeline_instances, :components_summary
80 if column_exists?(:pipeline_instances, :state)
81 remove_column :pipeline_instances, :state