forked from External/greenlight
GRN2-xx: Made role priority unique scoped to provider (#942)
* Made role priority unique scoped to provider * Fixed issues related to update_role after making role priority unique
This commit is contained in:
27
db/migrate/20200130144841_change_role_priority_to_unique.rb
Normal file
27
db/migrate/20200130144841_change_role_priority_to_unique.rb
Normal file
@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MigrationProduct < ActiveRecord::Base
|
||||
self.table_name = :roles
|
||||
end
|
||||
|
||||
class ChangeRolePriorityToUnique < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
MigrationProduct.where("priority < 0").where.not(name: "pending").each do |role|
|
||||
role.decrement!(:priority)
|
||||
end
|
||||
|
||||
add_index MigrationProduct, [:priority, :provider], unique: true
|
||||
end
|
||||
|
||||
dir.down do
|
||||
remove_index MigrationProduct, [:priority, :provider]
|
||||
|
||||
MigrationProduct.where("priority < 0").where.not(name: "pending").each do |role|
|
||||
role.increment!(:priority)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_11_28_212935) do
|
||||
ActiveRecord::Schema.define(version: 2020_01_30_144841) do
|
||||
|
||||
create_table "features", force: :cascade do |t|
|
||||
t.integer "setting_id"
|
||||
@ -58,6 +58,7 @@ ActiveRecord::Schema.define(version: 2019_11_28_212935) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["name", "provider"], name: "index_roles_on_name_and_provider", unique: true
|
||||
t.index ["name"], name: "index_roles_on_name"
|
||||
t.index ["priority", "provider"], name: "index_roles_on_priority_and_provider", unique: true
|
||||
end
|
||||
|
||||
create_table "rooms", force: :cascade do |t|
|
||||
|
Reference in New Issue
Block a user