Introduce a ConflictsForTalk model and db view

This commit is contained in:
Petko Bordjukov 2016-10-13 04:23:56 +03:00
parent 42582f79b3
commit b9e6a89f22
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,2 @@
class ConflictsForTalk < ApplicationRecord
end

View File

@ -0,0 +1,19 @@
CONFLICTS_FOR_TALK_VIEW_SQL = <<EOS
CREATE VIEW "conflicts_for_talks" AS
SELECT DISTINCT("left"."talk_id") AS "talk_id",
COUNT("right"."talk_preference_id") - 1 AS "conflicts"
FROM "selected_talks" AS "left"
INNER JOIN "selected_talks" AS "right"
ON "left"."talk_id" = "right"."talk_id"
GROUP BY "left"."id";
EOS
class AddConflictsForTalkView < ActiveRecord::Migration[5.0]
def up
execute CONFLICTS_FOR_TALK_VIEW_SQL
end
def down
execute 'DROP VIEW "conflicts_for_talks"'
end
end