-
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
Migrate Picture content from BinaryBlobs to Pictures table #153
Conversation
@miq-bot add_labels core enhancement gaprindashvili/yes |
@bdunne Cannot apply the following label because they are not recognized: core enhancement gaprindashvili/yes |
@@ -0,0 +1,51 @@ | |||
class MovePicturesBlobsToPictures < ActiveRecord::Migration[5.0] | |||
class BinaryBlob < ActiveRecord::Base | |||
has_many :binary_blob_parts, -> { order(:id) }, :dependent => :delete_all |
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.
needs the :class designation to ensure it uses the stub.
class MovePicturesBlobsToPictures < ActiveRecord::Migration[5.0] | ||
class BinaryBlob < ActiveRecord::Base | ||
has_many :binary_blob_parts, -> { order(:id) }, :dependent => :delete_all | ||
belongs_to :resource, :polymorphic => true |
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.
You don't need this.
add_column :pictures, :md5, :string | ||
|
||
say_with_time("Moving picture content from BinaryBlobs to the pictures table") do | ||
BinaryBlob.where(:resource_type => "Picture").all.each do |blob| |
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.
Let's change this to a find_each just to ensure we batch it properly just in case there are lot of these.
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 add a .includes(:binary_blob_parts)
to avoid an N+1?
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 also do you need in_my_region
? Even though they are not replicated, someone might have enabled that.
Picture.in_my_region.all.each do |picture| | ||
size = picture.content.try(:length).to_i | ||
|
||
BinaryBlob.create!( |
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.
We shouldn't create the binaryblob if the size is 0. Though that seems like a real edge case.
Checked commit bdunne@84cd462 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
|
happens during
(just these 2 fail in my db) Not sure if there can be other links to the blobs and these are still used or if this is an aritfact of something not getting deleted and we should just drop these..? |
How weird that you have nil pictures...that should not be possible, unless the original table was |
It could theoretically have to do with updating GenericObjectDefintion via the API to remove the picture. Looks like it does something along the lines of |
I'm holding off backporting to Gaprindashvili. Let me know if/when it's ok to backport. |
@jntullo ? |
@bdunne Can you update the PR to "deal with" resource_id being nil? However, separately, we should not be putting the DB in this state, so let's also fix whatever bug is causing this to happen. |
@Fryguy will look into that - also look into other seemingly related spec failures in the API. |
Migrate Picture content from BinaryBlobs to Pictures table (cherry picked from commit 91b0fc0) https://bugzilla.redhat.com/show_bug.cgi?id=1536046
Gaprindashvili backport details:
|
To be merged with: ManageIQ/manageiq#16810
https://bugzilla.redhat.com/show_bug.cgi?id=1532286