Skip to content

Commit 8ea7766

Browse files
committed
add unique index to group id
1 parent b83e78c commit 8ea7766

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

app/models/group_classifier_state.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ class GroupClassifierState < ApplicationRecord
1313
# find all classifiers for public, including group and username
1414
scope :for_public, -> { where(arel_table[:group_id].lteq(0)) }
1515
scope :for_group, -> { where("group_id < 0") }
16+
17+
validates :group_id, uniqueness: true
1618
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class AddUniqueIndexToGroupClassifierStatesGroupId < ActiveRecord::Migration[8.0]
2+
def change
3+
# Remove the old, non-unique index first.
4+
remove_index :group_classifier_states, name: "index_group_classifier_states_on_group_id"
5+
6+
# Now, add the new index with a uniqueness constraint.
7+
add_index :group_classifier_states, :group_id, unique: true
8+
end
9+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)