diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index d64bce9ac..cc5f7045e 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -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 } diff --git a/db/migrate/20171002103314_add_poll_shift_task_index.rb b/db/migrate/20171002103314_add_poll_shift_task_index.rb new file mode 100644 index 000000000..d15275556 --- /dev/null +++ b/db/migrate/20171002103314_add_poll_shift_task_index.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 500f03540..f6ff7447d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"