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

Added a new column to store embedded method names #14847

Merged
merged 5 commits into from
May 4, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/miq_ae_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class MiqAeMethod < ApplicationRecord
include MiqAeSetUserInfoMixin
include MiqAeYamlImportExportMixin
default_value_for :embedded_methods, []

belongs_to :ae_class, :class_name => "MiqAeClass", :foreign_key => :class_id
has_many :inputs, -> { order :priority }, :class_name => "MiqAeField", :foreign_key => :method_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEmbeddedMethodsToMiqAeMethod < ActiveRecord::Migration[5.0]
def change
add_column :miq_ae_methods, :embedded_methods, :text, :array => true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bdunne @Fryguy
For existing records #embedded_methods will return a nil but if we set the default value (:default => []) in the add_column field #embedded_methods will return a [].
That means in the code we don't have to check for nil values.
So my question is along with the model default_value_for should we set the add_column default.

Copy link
Member

Choose a reason for hiding this comment

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

@mkanoor It's my understanding that we avoid using postgres defaults for all columns and leave all of the default logic in ruby. So, you can add a line to this migration to populate the column on all existing records.

end
end
1 change: 1 addition & 0 deletions db/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4803,6 +4803,7 @@ miq_ae_methods:
- updated_on
- updated_by
- updated_by_user_id
- embedded_methods
miq_ae_namespaces:
- id
- parent_id
Expand Down