-
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
[WIP] Add type column to service_order table #328
Closed
Closed
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
16 changes: 16 additions & 0 deletions
16
db/migrate/20190123145942_add_type_column_to_service_order.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,16 @@ | ||
class AddTypeColumnToServiceOrder < ActiveRecord::Migration[5.0] | ||
def up | ||
add_column :service_order, :type, :string | ||
|
||
say_with_time("Set service_order type") do | ||
ServiceOrder.all.each do |service_order| | ||
type = service_order.miq_requests.pluck(:type).any? { |t| t === 'ServiceTemplateTransformationPlanRequest' } ? ServiceOrderV2V : ServiceOrderCart | ||
service_order.update_attribute(:type, type) | ||
end | ||
end | ||
end | ||
|
||
def down | ||
remove_column :service_order, :type | ||
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.
A few thoughts on these changes.
add_colum
andremove_column
referenceservice_order
instead ofservice_orders
(plural)update
instead ofupdate_attribute
type
column directly I would recommend disabling STI at the top of the migration withself.inheritance_column = :_type_disabled
in the class.service_order.miq_requests
call.ServiceOrderV2V : ServiceOrderCart
which are not merged yet and the migration will fail. (See [WIP] Use STI with ServiceOrder model manageiq#19766)Then I really started thinking about the changes and wanted to suggest the following migration replacement.
The basic premise is we get all the v2v Requests and do a single call to update the related ServiceOrders. Any ServiceOrders remaining will be cart orders, so we can update those by finding ones that have
type => nil
.Here's what I think the migration should look like: (
This still requires that ManageIQ/manageiq#19766 gets merged and I highly recommend tests be added to this PR before merging.
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.
Also need to update ManageIQ/manageiq#19766 to address the comment above (#328 (comment))
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.
It will also need some logic to make sure the v2v paths create the right kind