lib/generators/metka/strategies/view/templates/migration.rb.erb in metka-1.0.3 vs lib/generators/metka/strategies/view/templates/migration.rb.erb in metka-2.0.0

- old
+ new

@@ -2,17 +2,20 @@ class <%= @migration_class_name %> < ActiveRecord::Migration<%= ActiveRecord::VERSION::MAJOR < 5 ? '' : '[5.0]' %> def up execute <<-SQL CREATE OR REPLACE VIEW <%= view_name %> AS - - SELECT UNNEST - ( <%= source_column_name %> ) AS <%= source_column_name.singularize %>_name, - COUNT ( * ) AS taggings_count - FROM - <%= source_table_name %> - GROUP BY - <%= source_column_name.singularize %>_name; + 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