-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add deleted_on to ServiceTemplate for archival #207
Merged
Fryguy
merged 1 commit into
ManageIQ:master
from
agrare:add_deleted_on_to_service_templates
May 31, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
db/migrate/20180525171150_add_deleted_on_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,29 @@ | ||
class AddDeletedOnToServiceTemplate < ActiveRecord::Migration[5.0] | ||
class ServiceTemplate < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
|
||
include ReservedMigrationMixin | ||
include MigrationStubHelper | ||
end | ||
|
||
def up | ||
add_column :service_templates, :deleted_on, :datetime | ||
|
||
say_with_time("Migrate data from reserved table to service_templates") do | ||
ServiceTemplate.includes(:reserved_rec).each do |st| | ||
st.reserved_hash_migrate(:deleted_on) | ||
end | ||
end | ||
end | ||
|
||
def down | ||
say_with_time("Migrate data from service_templates to reserved table") do | ||
ServiceTemplate.includes(:reserved_rec).each do |st| | ||
st.reserved_hash_set(:deleted_on, st.deleted_on) | ||
st.save! | ||
end | ||
end | ||
|
||
remove_column :service_templates, :deleted_on | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
spec/migrations/20180525171150_add_deleted_on_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,48 @@ | ||
require_migration | ||
|
||
describe AddDeletedOnToServiceTemplate do | ||
let(:reserve_stub) { Spec::Support::MigrationStubs.reserved_stub } | ||
let(:service_template_stub) { migration_stub(:ServiceTemplate) } | ||
|
||
migration_context :up do | ||
it "Migrates Reserve data to ServiceTemplate" do | ||
deleted_on_time = Time.current | ||
|
||
st = service_template_stub.create! | ||
reserve_stub.create!( | ||
:resource_type => st.class.name, | ||
:resource_id => st.id, | ||
:reserved => { | ||
:deleted_on => deleted_on_time, | ||
} | ||
) | ||
|
||
migrate | ||
|
||
st.reload | ||
|
||
expect(reserve_stub.count).to eq(0) | ||
expect(st.deleted_on.to_s).to eq(deleted_on_time.to_s) | ||
end | ||
end | ||
|
||
migration_context :down do | ||
it "Migrates deleted_on in ServiceTemplate to Reserve table" do | ||
deleted_on_time = Time.current | ||
|
||
st = service_template_stub.create!( | ||
:deleted_on => deleted_on_time, | ||
) | ||
|
||
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[:deleted_on].to_s).to eq(deleted_on_time.to_s) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no reversed migrate method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope just https://github.com/ManageIQ/manageiq-schema/blob/master/lib/reserved_migration_mixin.rb#L6-L10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how all of our reserved table down migrations are today but I can write a reserved_hash_migrate down equivalent if you want.
reserved_hash_unmigrate/migrate_down
or something? It would just beself.reserved_hash_set(k, v); self.save!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird...oh well, we can make that for the future.