Skip to content
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

Create migrations to add resource_type row #302

Closed

Conversation

juliancheal
Copy link
Member

@juliancheal juliancheal commented Nov 8, 2018

Adds new row
Migrates existing data to the new row

This PR needs to be merged in order see issue for ordering ManageIQ/manageiq#18222

@juliancheal juliancheal force-pushed the create_resource_type_column branch from 29bfbe0 to a061d31 Compare November 8, 2018 20:38
@jrafanie
Copy link
Member

jrafanie commented Nov 14, 2018

@juliancheal how hard is it to get all the callers to use the new column? If we merge this, they'll be looking for towhat column, which no longer exists. It feels like we might need to:

  • add the new column, resource_type
  • override towhat to read_attribute(:towhat) || read_attribute(:resource_type)
  • migrate the data from towhat to resource_type
  • change callers to use resource_type
  • Drop the override for towhat in step 2

Thoughts?

@juliancheal
Copy link
Member Author

@jrafanie

override towhat to read_attribute(:towhat) || read_attribute(:resource_type)

Is a great idea. Apart from tests for this PR and adding that above line, I think in the core and ui repos i've removed all the callers (that i know of) to towhat.

This sounds like a good way to proceed.

@jrafanie
Copy link
Member

@juliancheal just remind people on the PRs, the order of the PRs and why you're doing it in that order. It's an abnormal procedure so forgetful me or others might question it.

@juliancheal
Copy link
Member Author

@juliancheal just remind people on the PRs, the order of the PRs and why you're doing it in that order. It's an abnormal procedure so forgetful me or others might question it.

Created an issue to list the order ManageIQ/manageiq#18222

@juliancheal juliancheal force-pushed the create_resource_type_column branch 4 times, most recently from a81d116 to 2b9aca7 Compare November 21, 2018 16:46
Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only have a few minor comments. 🇺🇸


def up
say_with_time("Moving MiqPolicy towhat to resource type") do
MiqPolicy.all.each do |policy|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think there's too many, but maybe we want find_each

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or eventually one sql query MiqPolicy.update_all('resource_type = resource_type')

say_with_time("Moving MiqPolicy towhat to resource type") do
MiqPolicy.all.each do |policy|
policy.resource_type = policy.towhat
policy.save
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

policy.update(:resource_type => policy.towhat)

say_with_time("Moving MiqPolicy resource type to towhat") do
MiqPolicy.all.each do |policy|
policy.towhat = policy.resource_type
policy.save
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

say_with_time("Moving Condition towhat to resource type") do
Condition.all.each do |condition|
condition.resource_type = condition.towhat
condition.save
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

say_with_time("Moving Condition resource type to towhat") do
Condition.all.each do |condition|
condition.towhat = condition.resource_type
condition.save
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


migrate

expect(miq_policy.reload).to eq(:resource_type => "ContainerImage")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(miq_policy.reload.resource_type).to eq("ContainerImage")


migrate

expect(miq_policy.reload).to eq(:resource_type => "ContainerImage")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


migrate

expect(condition.reload).to eq(:resource_type => "ContainerImage")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


migrate

expect(condition.reload).to eq(:resource_type => "ContainerImage")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@juliancheal juliancheal force-pushed the create_resource_type_column branch 4 times, most recently from 9616d6a to fd8b0bf Compare November 21, 2018 17:38
Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@@ -0,0 +1,21 @@
class MigrateMiqPolicyTowhatToResourceType < ActiveRecord::Migration[5.0]
class MiqPolicy < ActiveRecord::Base
self.inheritance_column = :_type_disabled
Copy link
Contributor

@lpichler lpichler Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not needed for MiqPolicy as there is no MiqPolicy#type column, see: #4 (comment)

@@ -0,0 +1,21 @@
class MigrateConditionsTowHatToResourceType < ActiveRecord::Migration[5.0]
class Condition < ActiveRecord::Base
self.inheritance_column = :_type_disabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here , it is not needed #4 (comment)

@lpichler
Copy link
Contributor

LGTM and I had also some minor comments 🇨🇿 😄

Adds new row
Migrates existing data to the new row
@juliancheal juliancheal force-pushed the create_resource_type_column branch from fd8b0bf to ae1f208 Compare November 21, 2018 23:20
@juliancheal
Copy link
Member Author

@jrafanie seeing as you're off next week, shall we put a pin in this until you return?

@jrafanie
Copy link
Member

LGTM, I can't merge here but it looks good. @juliancheal you can work with @bdunne or @carbonin, I believe if they're good with the approach, it will be fine to do while I'm away.

@miq-bot
Copy link
Member

miq-bot commented Nov 22, 2018

Checked commit juliancheal@ae1f208 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 0 offenses detected
Everything looks fine. ⭐

juliancheal pushed a commit to juliancheal/manageiq-schema that referenced this pull request Dec 11, 2018
Migration of data already happend in PR ManageIQ#302
@juliancheal
Copy link
Member Author

@miq-bot add_label technical debt

@bdunne
Copy link
Member

bdunne commented Dec 11, 2018

Any reason not to rename_column? It would be much faster and avoid the triple migration (create, migrate data, delete). We could deprecate_attribute on the model side as well.

@juliancheal
Copy link
Member Author

Any reason not to rename_column? It would be much faster and avoid the triple migration (create, migrate data, delete). We could deprecate_attribute on the model side as well.

@bdunne I'm sure there is a reason @jrafanie?

@jrafanie
Copy link
Member

Any reason not to rename_column? It would be much faster and avoid the triple migration (create, migrate data, delete). We could deprecate_attribute on the model side as well.

The only reason is that we can't rename the column and change the caller code in core and ui-classic all in one PR. The core and ui-classic PRs depend on the resource_type existing so they can't go green until the column is created.

@jrafanie
Copy link
Member

The idea was to:

  • create the resource_type column (get it merged)
  • create the core, ui-classic and schema (data migration) PRs, get them all green, then merge together
  • then drop the column

@bdunne
Copy link
Member

bdunne commented Dec 11, 2018

My concerns about doing it the proposed way are:

  • For a short time we'll have 2 columns with the same data (hopefully), if they're different which one is correct?
  • There's not just 2 repos (core and ui-classic), so merging schema and core (with the deprecation) at the same time would be fairly easy. Merging 3 or more repos at the same time will be much more complicated.
  • Touching every record seems unnecessary

@jrafanie
Copy link
Member

The intent is to create the column, leave it unused, get the 3 co-dependent PRs to use/migrate to the new column merged together, then drop the column.

I'm not sure how to do rename column with two other repos needing to use the new or old column based on the schema version. How do you suggest we do that? The core and ui-classic PRs can't become green until the column is renamed so you can't time them to use the correct column until they're green and merged.

@juliancheal
Copy link
Member Author

After speaking with @bdunne and @jrafanie we have a plan!

@juliancheal
Copy link
Member Author

Closing in favour of #312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants