# frozen_string_literal: true class <%= @migration_class_name %> < ActiveRecord::Migration<%= ActiveRecord::VERSION::MAJOR < 5 ? '' : '[5.0]' %> def up execute <<-SQL CREATE OR REPLACE VIEW <%= view_name %> AS SELECT tag_name, COUNT(*) AS taggings_count FROM ( SELECT UNNEST (<%= source_columns.join(' || ') %>) AS tag_name FROM <%= source_table_name %> ) subquery GROUP BY tag_name; SQL end def down execute <<-SQL DROP VIEW <%= view_name %>; SQL end end