Skip to content

Commit

Permalink
Remove default_value_for usage where database defaults can be used
Browse files Browse the repository at this point in the history
Depends on ManageIQ/manageiq-schema#721

Some of the remaining ones have custom defaults in STI or STI-like
subclasses, meaning we can't easily replace these with db defaults.

Defaults set in a subclass, not base class, in STI/STI like behavior:

  app/models/miq_provision_request.rb:  default_value_for :source_type,  "VmOrTemplate"
  app/models/service_template_provision_request.rb:  default_value_for :process,      false (overrides base class default)
  manageiq/providers/embedded_automation_manager/configuration_script_source.rb:  attribute :scm_type, :default => "git"
  manageiq/providers/embedded_automation_manager/configuration_script_source.rb:  attribute :scm_branch, :default => "master"

  manageiq/providers/cloud_manager/template.rb:  attribute :cloud, :default => true
  manageiq/providers/cloud_manager/vm.rb:  attribute :cloud, :default => true
  manageiq/providers/infra_manager/template.rb:  attribute :cloud, :default => false
  manageiq/providers/infra_manager/vm.rb:  attribute :cloud, :default => false
  manageiq/providers/physical_infra_manager/vm.rb:  attribute :cloud, :default => false

  app/models/service_retire_task.rb:  default_value_for :request_type, "service_retire"
  app/models/vm_migrate_task.rb:  default_value_for :request_type, "vm_migrate"
  app/models/vm_retire_task.rb:  default_value_for :request_type, "vm_retire"

  service_reconfigure_request.rb:  attribute :source_type, :default => SOURCE_CLASS_NAME
  service_template_provision_request.rb:  attribute :source_type, :default => SOURCE_CLASS_NAME
  vm_retire_request.rb:  attribute :source_type, :default => SOURCE_CLASS_NAME
  change_column_default :orchestration_stack_retire_tasks, :request_type,  :from => nil, :to => "orchestration_stack_retire"

Others, use block notation and isn't replaceable with database defaults.
We tried attribute defaults before but they trigger "changes" when the defaults
get set, which leads to unexpected changes in behavior.
  • Loading branch information
jrafanie committed Feb 29, 2024
1 parent 760f8df commit 7fc7ec4
Show file tree
Hide file tree
Showing 30 changed files with 0 additions and 72 deletions.
2 changes: 0 additions & 2 deletions app/models/assigned_server_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class AssignedServerRole < ApplicationRecord
belongs_to :miq_server
belongs_to :server_role

default_value_for :active, false

delegate :master_supported?, :name, :to => :server_role

HIGH_PRIORITY = 1
Expand Down
1 change: 0 additions & 1 deletion app/models/blacklisted_event.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class BlacklistedEvent < ApplicationRecord
belongs_to :ext_management_system, :foreign_key => "ems_id"

default_value_for :enabled, true
after_save :reload_all_server_settings
after_destroy :reload_all_server_settings, :audit_deletion
after_create :audit_creation
Expand Down
5 changes: 0 additions & 5 deletions app/models/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class Classification < ApplicationRecord

DEFAULT_NAMESPACE = "/managed".freeze

default_value_for :read_only, false
default_value_for :syntax, "string"
default_value_for :single_value, false
default_value_for :show, true

FIXTURE_FILE = FIXTURE_DIR.join("classifications.yml")

def self.hash_all_by_type_and_name(conditions = {})
Expand Down
2 changes: 0 additions & 2 deletions app/models/cloud_database_flavor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ class CloudDatabaseFlavor < ApplicationRecord

virtual_total :total_cloud_databases, :cloud_databases

default_value_for :enabled, true

scope :active, -> { where(:enabled => true) }
end
1 change: 0 additions & 1 deletion app/models/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Dialog < ApplicationRecord
# The following gets around a glob symbolic link issue
YAML_FILES_PATTERN = "{,*/**/}*.{yaml,yml}".freeze

default_value_for :system, false
has_many :dialog_tabs, -> { order(:position) }, :dependent => :destroy
validate :validate_children

Expand Down
3 changes: 0 additions & 3 deletions app/models/dialog_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ class DialogField < ApplicationRecord
validates :name, :exclusion => {:in => %w(action controller),
:message => "Field Name %{value} is reserved."}

default_value_for :required, false
default_value_for(:visible) { true }
validates :visible, inclusion: { in: [ true, false ] }
default_value_for :load_values_on_init, true

serialize :values
serialize :values_method_options, Hash
Expand Down
1 change: 0 additions & 1 deletion app/models/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class Endpoint < ApplicationRecord
belongs_to :resource, :polymorphic => true

default_value_for :verify_ssl, OpenSSL::SSL::VERIFY_PEER
validates :verify_ssl, :inclusion => {:in => [OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER]}
validates :port, :numericality => {:only_integer => true, :allow_nil => true, :greater_than => 0}
validates :url, :uniqueness_when_changed => true, :allow_blank => true, :unless => :allow_duplicate_url?
Expand Down
2 changes: 0 additions & 2 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ def validate_zone_not_maintenance_when_ems_enabled?
alias_method :clusters, :ems_clusters # Used by web-services to return clusters as the property name
alias_attribute :to_s, :name

default_value_for :enabled, true

# Move ems to maintenance zone and backup current one
# @param orig_zone [Integer] because of zone of child manager can be changed by parent manager's ensure_managers() callback
# we need to specify original zone for children explicitly
Expand Down
2 changes: 0 additions & 2 deletions app/models/flavor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Flavor < ApplicationRecord

virtual_total :total_vms, :vms

default_value_for :enabled, true

alias_attribute :cpus, :cpu_total_cores
alias_attribute :cpu_cores, :cpu_cores_per_socket

Expand Down
1 change: 0 additions & 1 deletion app/models/git_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class GitRepository < ApplicationRecord

validates :url, :format => Regexp.union(URI.regexp(%w[http https file ssh]), /\A[-\w:.]+@.*:/), :allow_nil => false

default_value_for :verify_ssl, OpenSSL::SSL::VERIFY_PEER
validates :verify_ssl, :inclusion => {:in => [OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER]}

has_many :git_branches, :dependent => :destroy
Expand Down
2 changes: 0 additions & 2 deletions app/models/miq_approval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class MiqApproval < ApplicationRecord
belongs_to :stamper, :class_name => "User"
belongs_to :miq_request

default_value_for :state, "pending"

def approver=(approver)
super
self.approver_name = approver.try(:name)
Expand Down
1 change: 0 additions & 1 deletion app/models/miq_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MiqGroup < ApplicationRecord

serialize :settings

default_value_for :group_type, USER_GROUP
default_value_for(:sequence) { next_sequence }

acts_as_miq_taggable
Expand Down
4 changes: 0 additions & 4 deletions app/models/miq_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ def self.policy_modes
include YamlImportExportMixin
before_validation :default_name_to_guid, :on => :create

default_value_for :towhat, 'Vm'
default_value_for :active, true
default_value_for :mode, 'control'

# NOTE: If another class references MiqPolicy through an ActiveRecord association,
# particularly has_one and belongs_to, calling .conditions will result in
# that method being directly called on the proxy object, as opposed to the
Expand Down
4 changes: 0 additions & 4 deletions app/models/miq_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ class MiqRequest < ApplicationRecord
serialize :options, Hash

default_value_for(:message) { |r| "#{r.class::TASK_DESCRIPTION} - Request Created" }
default_value_for :request_state, 'pending'

default_value_for(:request_type) { |r| r.request_types.first }
default_value_for :status, 'Ok'
default_value_for :process, true

validates_inclusion_of :approval_state, :in => %w(pending_approval approved denied), :message => "should be 'pending_approval', 'approved' or 'denied'"
validates_inclusion_of :status, :in => %w(Ok Warn Error Timeout Denied)
Expand Down
3 changes: 0 additions & 3 deletions app/models/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class MiqRequestTask < ApplicationRecord
serialize :phase_context, Hash
serialize :options, Hash

default_value_for :state, 'pending'
default_value_for :status, 'Ok'

delegate :request_class, :task_description, :to => :class

validates_inclusion_of :status, :in => %w( Ok Warn Error Timeout )
Expand Down
2 changes: 0 additions & 2 deletions app/models/miq_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class MiqSchedule < ApplicationRecord
ALLOWED_CLASS_METHOD_ACTIONS = %w[automation_request].freeze
IMPORT_CLASS_NAMES = %w[MiqSchedule].freeze

default_value_for :userid, "system"
default_value_for :enabled, true
default_value_for(:zone_id) { MiqServer.my_server.zone_id }

def set_start_time_and_prod_default
Expand Down
1 change: 0 additions & 1 deletion app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class MiqServer < ApplicationRecord
before_destroy :validate_is_deleteable
after_destroy :destroy_linked_events_queue

default_value_for(:name, "EVM")
default_value_for(:zone) { Zone.default_zone }

scope :active_miq_servers, -> { where(:status => STATUSES_ACTIVE) }
Expand Down
2 changes: 0 additions & 2 deletions app/models/miq_user_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class MiqUserRole < ApplicationRecord

serialize :settings

default_value_for :read_only, false

FIXTURE_PATH = File.join(FIXTURE_DIR, table_name)
FIXTURE_YAML = "#{FIXTURE_PATH}.yml"

Expand Down
3 changes: 0 additions & 3 deletions app/models/miq_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
class MiqWidget < ApplicationRecord
include ReadOnlyMixin

default_value_for :enabled, true
default_value_for :read_only, false

DEFAULT_ROW_COUNT = 5
IMPORT_CLASS_NAMES = %w(MiqWidget).freeze

Expand Down
1 change: 0 additions & 1 deletion app/models/notification_recipient.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class NotificationRecipient < ApplicationRecord
belongs_to :notification
belongs_to :user
default_value_for :seen, false
virtual_column :details, :type => :string

scope :unseen, -> { where(:seen => false) }
Expand Down
3 changes: 0 additions & 3 deletions app/models/orchestration_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ class OrchestrationTemplate < ApplicationRecord
has_many :stacks, :class_name => "OrchestrationStack"
has_one :picture, :dependent => :destroy, :as => :resource, :autosave => true

default_value_for :draft, false
default_value_for :orderable, true

validates :md5,
:uniqueness_when_changed => {:scope => :draft, :message => "of content already exists (content must be unique)"},
:if => :unique_md5?
Expand Down
2 changes: 0 additions & 2 deletions app/models/pxe_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class PxeServer < ApplicationRecord

alias_attribute :description, :name

default_value_for :customization_directory, ""

serialize :visibility

acts_as_miq_taggable
Expand Down
5 changes: 0 additions & 5 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ class Service < ApplicationRecord

validates :name, :presence => true

default_value_for :visible, false
default_value_for :initiator, 'user'
default_value_for :lifecycle_state, 'unprovisioned'
default_value_for :retired, false

validates :visible, :inclusion => { :in => [true, false] }
validates :retired, :inclusion => { :in => [true, false] }

Expand Down
5 changes: 0 additions & 5 deletions app/models/service_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ class ServiceResource < ApplicationRecord
belongs_to :resource, :polymorphic => true
belongs_to :source, :polymorphic => true

default_value_for :group_idx, 0
default_value_for :scaling_min, 1
default_value_for :scaling_max, -1
default_value_for :provision_index, 0

virtual_column :resource_name, :type => :string
virtual_column :resource_description, :type => :string

Expand Down
2 changes: 0 additions & 2 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class ServiceTemplate < ApplicationRecord
virtual_column :archived, :type => :boolean
virtual_column :active, :type => :boolean

default_value_for :internal, false
default_value_for :service_type, SERVICE_TYPE_ATOMIC
default_value_for(:generic_subtype) { |st| 'custom' if st.prov_type == 'generic' }

virtual_has_one :config_info, :class_name => "Hash"
Expand Down
2 changes: 0 additions & 2 deletions app/models/share.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Share < ApplicationRecord
validates :tenant, :presence => true
validates :user, :presence => true

default_value_for :allow_tenant_inheritance, false

scope :by_tenant_inheritance, ->(tenant) do
where(:tenant => tenant.accessible_tenant_ids(:ancestor_ids),
:allow_tenant_inheritance => true)
Expand Down
2 changes: 0 additions & 2 deletions app/models/system_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class SystemConsole < ApplicationRecord
belongs_to :vm
belongs_to :user

default_value_for :opened, false

validates :url_secret, :uniqueness_when_changed => true

def connection_params
Expand Down
5 changes: 0 additions & 5 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class Tenant < ApplicationRecord

acts_as_miq_taggable

default_value_for :name, "My Company"
default_value_for :description, "Tenant for My Company"
default_value_for :divisible, true
default_value_for :use_config_for_attributes, false

before_destroy :ensure_can_be_destroyed

has_ancestry(:orphan_strategy => :restrict)
Expand Down
2 changes: 0 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class User < ApplicationRecord

serialize :settings, Hash # Implement settings column as a hash

default_value_for :failed_login_attempts, 0

scope :in_all_regions, ->(id) { where(:userid => User.default_scoped.where(:id => id).select(:userid)) }

def self.with_roles_excluding(identifier, allowed_ids: nil)
Expand Down
1 change: 0 additions & 1 deletion app/models/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Zone < ApplicationRecord
include ConfigurationManagementMixin

scope :visible, -> { where(:visible => true) }
default_value_for :visible, true

def active_miq_servers
MiqServer.active_miq_servers.where(:zone_id => id)
Expand Down

0 comments on commit 7fc7ec4

Please sign in to comment.