-
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
Update default of internal attribute in service template #251
Conversation
6aaf80a
to
bacf917
Compare
@bzwei @gmcculloug @bdunne @carbonin Please review. |
end | ||
|
||
def up | ||
change_column :service_templates, :internal, :boolean |
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.
In this case you would add_column
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.
@bdunne the column already exists
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.
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.
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.
The column is already a boolean type. Why are we doing this change_column
at 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.
We only change the default value here. I will remove change_column
end | ||
|
||
def down | ||
change_column :service_templates, :internal, :boolean |
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.
In this case you would use remove_column
.
|
||
def down | ||
change_column :service_templates, :internal, :boolean | ||
say_with_time("Set ServiceTemplate internal") do |
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.
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') |
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 need to create two service templates, one with type ServiceTemplateTransformationPlan
, the other not.
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.
Like @gmcculloug mentioned, the ServiceTemplateTransformationPlan
type has been tested in PR #238. I'll only keep the test for up migration.
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'll still need to test for ServiceTemplateTransformationPlan
to prove it does not get modified by this migration.
end | ||
end | ||
|
||
def down |
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 don't need down
. It was a bug. We should set the column to nil
at 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.
+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.
PR #238 is already doing the work to set the Can this just be an up migration that does: |
class ServiceTemplate < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
|
||
include MigrationStubHelper |
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.
bacf917
to
c0d9f20
Compare
This is getting confusing. Are you trying to: If A, prefer default_value_for in the model. |
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 |
The public_service_templates scope is not returning any records where |
Oh, that's annoying :/ |
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 |
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 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
fdd3301
to
b1bbdbc
Compare
b1bbdbc
to
296d944
Compare
@miq-bot add_label blocker |
@hsong-rh if this can be backported, can you add the gaprindashvili/yes label. |
Checked commit hsong-rh@296d944 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 db/migrate/20180810144738_update_default_internal_attribute.rb
|
@JPrause we don't backport migrations |
@Fryguy thanks,..that was my bad. I overlooked what repo this was. 😢 |
@Fryguy Can you approve and merge this? thanks. |
Change default value of internal attribute in service template to false.