-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from hsong-rh/add_internal_to_service_template
Add internal column to ServiceTemplate table
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
db/migrate/20180719163110_add_internal_to_service_template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class AddInternalToServiceTemplate < ActiveRecord::Migration[5.0] | ||
class ServiceTemplate < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
|
||
include ReservedMigrationMixin | ||
include MigrationStubHelper | ||
end | ||
|
||
def up | ||
add_column :service_templates, :internal, :boolean | ||
|
||
say_with_time("Migrate data from reserved table to ServiceTemplate") do | ||
ServiceTemplate.includes(:reserved_rec).where(:type => "ServiceTemplateTransformationPlan").each do |st| | ||
st.reserved_hash_migrate(:internal) | ||
end | ||
end | ||
|
||
say_with_time("Set ServiceTemplate internal") do | ||
ServiceTemplate.where(:type => "ServiceTemplateTransformationPlan").update_all(:internal => true) | ||
end | ||
end | ||
|
||
def down | ||
say_with_time("Migrate data from ServiceTemplate to reserved table") do | ||
ServiceTemplate.includes(:reserved_rec).where(:type => "ServiceTemplateTransformationPlan").each do |st| | ||
st.reserved_hash_set(:internal, st.internal) | ||
st.save! | ||
end | ||
end | ||
|
||
remove_column :service_templates, :internal | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
spec/migrations/20180719163110_add_internal_to_service_template_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require_migration | ||
|
||
describe AddInternalToServiceTemplate do | ||
let(:reserve_stub) { Spec::Support::MigrationStubs.reserved_stub } | ||
let(:service_template_stub) { migration_stub(:ServiceTemplate) } | ||
|
||
migration_context :up do | ||
it "sets internal to true when type is ServiceTemplateTransformationPlan" do | ||
st = service_template_stub.create!(:type => 'ServiceTemplateTransformationPlan') | ||
|
||
migrate | ||
|
||
expect(st.reload.internal).to be_truthy | ||
end | ||
|
||
it "migrate reserve data to ServiceTemplate" do | ||
st = service_template_stub.create!(:type => 'ServiceTemplateTransformationPlan') | ||
reserve_stub.create!( | ||
:resource_type => st.class.name, | ||
:resource_id => st.id, | ||
:reserved => { | ||
:internal => true, | ||
} | ||
) | ||
|
||
migrate | ||
|
||
st.reload | ||
expect(reserve_stub.count).to eq(0) | ||
expect(st.internal).to be_truthy | ||
end | ||
end | ||
|
||
migration_context :down do | ||
it "migrate internal in ServiceTemplate to reserve table" do | ||
st = service_template_stub.create!(:type => 'ServiceTemplateTransformationPlan', :internal => true) | ||
|
||
migrate | ||
|
||
expect(reserve_stub.count).to eq(1) | ||
|
||
reserved_rec = reserve_stub.first | ||
expect(reserved_rec.resource_id).to eq(st.id) | ||
expect(reserved_rec.resource_type).to eq(st.class.name) | ||
|
||
expect(reserved_rec.reserved[:internal]).to be_truthy | ||
end | ||
end | ||
end |