gauge/db/migrate/20161013011420_add_conflicts_for_talk_view.rb
2016-10-13 04:42:18 +03:00

20 lines
588 B
Ruby

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