Add task to unique triple index on Shift for booth, officer and task

This commit is contained in:
Bertocq
2017-10-02 13:45:19 +02:00
parent 1c85c8af79
commit 35f6a5bb65
3 changed files with 11 additions and 3 deletions

View File

@@ -6,8 +6,8 @@ class Poll
validates :booth_id, presence: true
validates :officer_id, presence: true
validates :date, presence: true
validates :date, uniqueness: { scope: [:officer_id, :booth_id] }
validates :task, presence: true
validates :date, uniqueness: { scope: [:officer_id, :booth_id, :task] }
enum task: { vote_collection: 0, recount_scrutiny: 1 }

View File

@@ -0,0 +1,7 @@
class AddPollShiftTaskIndex < ActiveRecord::Migration
def change
remove_index "poll_shifts", name: "index_poll_shifts_on_booth_id_and_officer_id"
add_index :poll_shifts, :task
add_index :poll_shifts, [:booth_id, :officer_id, :task], unique: true
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170927110953) do
ActiveRecord::Schema.define(version: 20171002103314) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -701,9 +701,10 @@ ActiveRecord::Schema.define(version: 20170927110953) do
t.integer "task", default: 0, null: false
end
add_index "poll_shifts", ["booth_id", "officer_id"], name: "index_poll_shifts_on_booth_id_and_officer_id", using: :btree
add_index "poll_shifts", ["booth_id", "officer_id", "task"], name: "index_poll_shifts_on_booth_id_and_officer_id_and_task", unique: true, using: :btree
add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree
add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree
add_index "poll_shifts", ["task"], name: "index_poll_shifts_on_task", using: :btree
create_table "poll_total_results", force: :cascade do |t|
t.integer "author_id"