Skip to content

Commit

Permalink
Create migrations to add resource_type row
Browse files Browse the repository at this point in the history
Adds new row
Migrates existing data to the new row
  • Loading branch information
Julian Cheal committed Nov 8, 2018
1 parent 41e477e commit a061d31
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddResourceTypeToMiqPolicyAndCondition < ActiveRecord::Migration[5.0]
def change
add_column :miq_policies, :resource_type, :string
add_column :conditions, :resource_type, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class MigrateMiqPolicyTowhatDataToResourceType < ActiveRecord::Migration[5.0]

class MiqPolicy < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

def up
say_with_time("Moving MiqPolicy towhat to resource type") do
MiqPolicy.all.each do |policy|
policy.resource_type = policy.towhat
policy.save
end
end
end

def down
say_with_time("Moving MiqPolicy resource type to towhat") do
MiqPolicy.all.each do |policy|
policy.towhat = policy.resource_type
policy.save
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class MigrateConditionsTowhatDataToResourceType < ActiveRecord::Migration[5.0]

class Condition < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end

def up
say_with_time("Moving Condition towhat to resource type") do
Condition.all.each do |condition|
condition.resource_type = condition.towhat
condition.save
end
end
end

def down
say_with_time("Moving Condition resource type to towhat") do
Condition.all.each do |condition|
condition.towhat = condition.resource_type
condition.save
end
end
end
end

0 comments on commit a061d31

Please sign in to comment.