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

Update default of internal attribute in service template #251

Merged
merged 1 commit into from
Aug 21, 2018

Conversation

hsong-rh
Copy link
Contributor

Change default value of internal attribute in service template to false.

@hsong-rh hsong-rh force-pushed the update_internal_default branch from 6aaf80a to bacf917 Compare August 10, 2018 16:45
@hsong-rh
Copy link
Contributor Author

@bzwei @gmcculloug @bdunne @carbonin Please review.

end

def up
change_column :service_templates, :internal, :boolean
Copy link
Member

Choose a reason for hiding this comment

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

In this case you would add_column

Copy link
Contributor

Choose a reason for hiding this comment

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

@bdunne the column already exists

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't fully understand. We may not need this line at all. We don't change the column property, but only migrate the values.

Copy link
Member

Choose a reason for hiding this comment

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

The column is already a boolean type. Why are we doing this change_column at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only change the default value here. I will remove change_column

end

def down
change_column :service_templates, :internal, :boolean
Copy link
Member

Choose a reason for hiding this comment

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

In this case you would use remove_column.


def down
change_column :service_templates, :internal, :boolean
say_with_time("Set ServiceTemplate internal") do
Copy link
Member

Choose a reason for hiding this comment

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

Since the column is being removed, there is no data migration required.


migration_context :up do
it "sets internal to false when type is not ServiceTemplateTransformationPlan" do
st = service_template_stub.create!(:type => 'OtherServiceTemplateTransformationPlan')
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to create two service templates, one with type ServiceTemplateTransformationPlan, the other not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like @gmcculloug mentioned, the ServiceTemplateTransformationPlan type has been tested in PR #238. I'll only keep the test for up migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll still need to test for ServiceTemplateTransformationPlan to prove it does not get modified by this migration.

end
end

def down
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need down. It was a bug. We should set the column to nil at all.

Copy link
Member

Choose a reason for hiding this comment

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

+1 I don't think this migration should have a down because we don't want to put the data back into a bad state.

@gmcculloug
Copy link
Member

PR #238 is already doing the work to set the internal column for ServiceTemplateTransformationPlan types.

Can this just be an up migration that does: ServiceTemplate.where(:internal => nil).update_all(:internal => false)

class ServiceTemplate < ActiveRecord::Base
self.inheritance_column = :_type_disabled

include MigrationStubHelper
Copy link
Member

Choose a reason for hiding this comment

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

I think this is only needed if you're using relations in the stub. Since you're only editing rows in the service_templates table I don't think this is needed.

@Fryguy @bdunne keep me honest here.

@hsong-rh hsong-rh force-pushed the update_internal_default branch from bacf917 to c0d9f20 Compare August 10, 2018 18:02
@bdunne
Copy link
Member

bdunne commented Aug 10, 2018

This is getting confusing. Are you trying to:
A: set column defaults in Postgres
-or-
B: update existing records from nil to false?

If A, prefer default_value_for in the model.
If B, I think that should just be an edit to the migration added in #238

@Fryguy
Copy link
Member

Fryguy commented Aug 10, 2018

This seems unnecessary as nil is falsey...existing record will be internal => nil, which is falsey.

@bdunne
Copy link
Member

bdunne commented Aug 10, 2018

This seems unnecessary as nil is falsey...existing record will be internal => nil, which is falsey.

The only problem is on the model side to query for non-internal records you need ServiceTemplate.where(:internal => [nil, false]) rather than ServiceTemplate.where(:internal => false)

@gmcculloug
Copy link
Member

The public_service_templates scope is not returning any records where internal = nil. And since we are using default_value_for on the base ServiceTemplate model it seemed better to update the nil records instead of adjusting the scope to compensate for nil.

@hsong-rh
Copy link
Contributor Author

@bdunne We are in the case of B: update existing records. So you want me reopen #238 to add this?

@bdunne
Copy link
Member

bdunne commented Aug 10, 2018

Since the migration in #238 hasn't been released yet and it feels like it was missed in the original migration, I think that's the right direction. @carbonin @Fryguy any objections to that?

@hsong-rh
Copy link
Contributor Author

@carbonin @Fryguy Do you agreed with @bdunne? If you do, I will reopen #238 to add this fix.

@Fryguy
Copy link
Member

Fryguy commented Aug 10, 2018

Oh, that's annoying :/

@Fryguy
Copy link
Member

Fryguy commented Aug 10, 2018

Ok, then this PR is correct. We should not modify existing migrations that change their functionality after they've been merged, because it's likely they've already been executed by developers. (modifying for performance or bug fixes doesn't change what the original migration did, so those are ok, but this doesn't fall into that category, IMO).


migrate

expect(st.reload.internal).to be_falsey
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong, because without your PR, this test would pass anyway (because nil is falsey). This should say .to be false to show you want the literal false value

@hsong-rh hsong-rh force-pushed the update_internal_default branch 2 times, most recently from fdd3301 to b1bbdbc Compare August 12, 2018 19:24
@hsong-rh hsong-rh force-pushed the update_internal_default branch from b1bbdbc to 296d944 Compare August 13, 2018 13:39
@JPrause
Copy link
Member

JPrause commented Aug 13, 2018

@miq-bot add_label blocker

@JPrause
Copy link
Member

JPrause commented Aug 13, 2018

@hsong-rh if this can be backported, can you add the gaprindashvili/yes label.

@miq-bot
Copy link
Member

miq-bot commented Aug 13, 2018

Checked commit hsong-rh@296d944 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 1 offense detected

db/migrate/20180810144738_update_default_internal_attribute.rb

@hsong-rh
Copy link
Contributor Author

@bdunne @Fryguy Please review and merge. Today is the last day for v2v build. Thanks.

@Fryguy
Copy link
Member

Fryguy commented Aug 13, 2018

@JPrause we don't backport migrations

@JPrause
Copy link
Member

JPrause commented Aug 13, 2018

@Fryguy thanks,..that was my bad. I overlooked what repo this was. 😢

@hsong-rh
Copy link
Contributor Author

@Fryguy Can you approve and merge this? thanks.

@Fryguy Fryguy merged commit ffe25c1 into ManageIQ:master Aug 21, 2018
@Fryguy Fryguy added this to the Sprint 93 Ending Aug 27, 2018 milestone Aug 21, 2018
@hsong-rh hsong-rh deleted the update_internal_default branch August 21, 2018 15:30
@Fryguy Fryguy added v2v and removed transformation labels Feb 28, 2020
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.

8 participants