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

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Apr 21, 2017

A new enhancement to add embedded method names to a miq_ae_method table.

To support changes in #14286

@mkanoor
Copy link
Contributor Author

mkanoor commented Apr 21, 2017

@Fryguy please review

@@ -0,0 +1,5 @@
class AddEmbeddedMethodsToMiqAeMethod < ActiveRecord::Migration[5.0]
def change
add_column :miq_ae_methods, :embedded_methods, :string, array: true, default: []
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 you want default_value_for in the model, not :default in the migration.

@@ -3,6 +3,8 @@
class MiqAeMethod < ApplicationRecord
include MiqAeSetUserInfoMixin
include MiqAeYamlImportExportMixin
serialize :embedded_methods, Array
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't have to serialize this because it's an Array column

@@ -0,0 +1,5 @@
class AddEmbeddedMethodsToMiqAeMethod < ActiveRecord::Migration[5.0]
def change
add_column :miq_ae_methods, :embedded_methods, :string, :array => true
Copy link
Member

Choose a reason for hiding this comment

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

How long could the data be? Should it be :text instead of :string?

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 It contains the method names and its possible that we could have lengths longer than 255 if they have a handful of methods defined. I have changed it to a text field.

Changed to use text instead of string
Removed the serialize
Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

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

👍 LGTM. Now it's up to @Fryguy (the schema master) :)

@mkanoor
Copy link
Contributor Author

mkanoor commented Apr 26, 2017

@Fryguy
Please review

@@ -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.

@miq-bot
Copy link
Member

miq-bot commented May 1, 2017

Checked commits mkanoor/manageiq@24e595f~...3da21cb with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 1 offense detected

db/migrate/20170421193150_add_embedded_methods_to_miq_ae_method.rb

@Fryguy Fryguy merged commit b712255 into ManageIQ:master May 4, 2017
@Fryguy Fryguy added this to the Sprint 60 Ending May 8, 2017 milestone May 4, 2017
@Fryguy Fryguy added the fine/no label May 4, 2017
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.

None yet

5 participants