1 class PipelineInstanceState < ActiveRecord::Migration
2 include CurrentApiClient
5 if !column_exists?(:pipeline_instances, :state)
6 add_column :pipeline_instances, :state, :string
9 if !column_exists?(:pipeline_instances, :components_summary)
10 add_column :pipeline_instances, :components_summary, :text
14 PipelineInstance.all.each do |pi|
15 pi.state = PipelineInstance::New
17 if !pi.attribute_present? :success # success is nil
18 if pi[:active] == true
19 pi.state = PipelineInstance::RunningOnServer
21 if pi.components_look_ready?
22 pi.state = PipelineInstance::Ready
24 pi.state = PipelineInstance::New
27 elsif pi[:success] == true
28 pi.state = PipelineInstance::Complete
30 pi.state = PipelineInstance::Failed
37 # We want to perform addition of state, and removal of active and success in two phases. Hence comment these statements out.
39 if column_exists?(:pipeline_instances, :active)
40 remove_column :pipeline_instances, :active
43 if column_exists?(:pipeline_instances, :success)
44 remove_column :pipeline_instances, :success
50 # We want to perform addition of state, and removal of active and success in two phases. Hence comment these statements out.
52 add_column :pipeline_instances, :success, :boolean, :null => true
53 add_column :pipeline_instances, :active, :boolean, :default => false
56 PipelineInstance.all.each do |pi|
58 when PipelineInstance::New, PipelineInstance::Ready
61 when PipelineInstance::RunningOnServer
64 when PipelineInstance::RunningOnClient
67 when PipelineInstance::Failed
70 when PipelineInstance::Complete
79 if column_exists?(:pipeline_instances, :components_summary)
80 remove_column :pipeline_instances, :components_summary
83 if column_exists?(:pipeline_instances, :state)
84 remove_column :pipeline_instances, :state