[PATCH conductor] BZ848671: Add unique constraints to ProviderPriorityGroup

Jan Provaznik jprovazn at redhat.com
Wed Aug 22 09:15:21 UTC 2012


On 08/17/2012 04:21 PM, ifarkas at redhat.com wrote:
> From: Imre Farkas <ifarkas at redhat.com>
>
> https://bugzilla.redhat.com/show_bug.cgi?id=848671
> ---
>   src/app/models/provider_priority_group.rb                     |  2 ++
>   ...0221_add_unique_constraints_to_provider_priority_groups.rb | 11 +++++++++++
>   2 files changed, 13 insertions(+)
>   create mode 100644 src/db/migrate/20120817130221_add_unique_constraints_to_provider_priority_groups.rb
>
> diff --git a/src/app/models/provider_priority_group.rb b/src/app/models/provider_priority_group.rb
> index 1e1a594..c17b959 100644
> --- a/src/app/models/provider_priority_group.rb
> +++ b/src/app/models/provider_priority_group.rb
> @@ -22,6 +22,8 @@ class ProviderPriorityGroup < ActiveRecord::Base
>     has_many :provider_accounts, :through => :provider_priority_group_elements, :source => :value, :source_type => 'ProviderAccount'
>
>     validates_numericality_of :score, :only_integer => true, :greater_than_or_equal_to => -100, :less_than_or_equal_to => 100
> +  validates_uniqueness_of :name, :scope => :pool_id
> +  validates_uniqueness_of :score, :scope => :pool_id
>
>     def include?(element)
>       if element.is_a?(Provider)
> diff --git a/src/db/migrate/20120817130221_add_unique_constraints_to_provider_priority_groups.rb b/src/db/migrate/20120817130221_add_unique_constraints_to_provider_priority_groups.rb
> new file mode 100644
> index 0000000..6a66b53
> --- /dev/null
> +++ b/src/db/migrate/20120817130221_add_unique_constraints_to_provider_priority_groups.rb
> @@ -0,0 +1,11 @@
> +class AddUniqueConstraintsToProviderPriorityGroups < ActiveRecord::Migration
> +  def self.up
> +    add_index :provider_priority_groups, [:name, :pool_id], :unique => true
> +    add_index :provider_priority_groups, [:score, :pool_id], :unique => true
> +  end
> +
> +  def self.down
> +    remove_index :provider_priority_groups, [:name, :pool_id]
> +    remove_index :provider_priority_groups, [:score, :pool_id]
> +  end
> +end
>

ACK



More information about the aeolus-devel mailing list