gauge/db/migrate/20161013023851_add_conflicts_view.rb
2016-10-13 06:10:56 +03:00

20 lines
614 B
Ruby

CONFLICTS_VIEW_SQL = <<EOS
CREATE VIEW "conflicts" AS
SELECT "left"."talk_id" AS left, "right"."talk_id" AS right, COUNT(*) AS "conflicts"
FROM "selected_talks" AS "left"
INNER JOIN "selected_talks" AS "right"
ON "left"."talk_preference_id" = "right"."talk_preference_id"
WHERE "left"."talk_id" != "right"."talk_id"
GROUP BY "left"."talk_id", "right"."talk_id";
EOS
class AddConflictsView < ActiveRecord::Migration[5.0]
def up
execute CONFLICTS_VIEW_SQL
end
def down
execute 'DROP VIEW "conflicts"'
end
end