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
13 PipelineInstance.reset_column_information
16 PipelineInstance.all.each do |pi|
17 pi.state = PipelineInstance::New
19 if !pi.attribute_present? :success # success is nil
20 if pi[:active] == true
21 pi.state = PipelineInstance::RunningOnServer
23 if pi.components_look_ready?
24 pi.state = PipelineInstance::Ready
26 pi.state = PipelineInstance::New
29 elsif pi[:success] == true
30 pi.state = PipelineInstance::Complete
32 pi.state = PipelineInstance::Failed
39 # We want to perform addition of state, and removal of active and success in two phases. Hence comment these statements out.
41 if column_exists?(:pipeline_instances, :active)
42 remove_column :pipeline_instances, :active
45 if column_exists?(:pipeline_instances, :success)
46 remove_column :pipeline_instances, :success
52 # We want to perform addition of state, and removal of active and success in two phases. Hence comment these statements out.
54 add_column :pipeline_instances, :success, :boolean, :null => true
55 add_column :pipeline_instances, :active, :boolean, :default => false
58 PipelineInstance.all.each do |pi|
60 when PipelineInstance::New, PipelineInstance::Ready
63 when PipelineInstance::RunningOnServer
66 when PipelineInstance::RunningOnClient
69 when PipelineInstance::Failed
72 when PipelineInstance::Complete
81 if column_exists?(:pipeline_instances, :components_summary)
82 remove_column :pipeline_instances, :components_summary
85 if column_exists?(:pipeline_instances, :state)
86 remove_column :pipeline_instances, :state