Kouhei Sutou
null+****@clear*****
Mon Aug 15 12:06:50 JST 2016
Kouhei Sutou 2016-08-15 12:06:50 +0900 (Mon, 15 Aug 2016) New Revision: 1a1c33e04223785f8439ea66bf3df2711b1328a0 https://github.com/groonga/groonga-schema/commit/1a1c33e04223785f8439ea66bf3df2711b1328a0 Message: Support outputting removed columns Modified files: lib/groonga-schema/column.rb lib/groonga-schema/diff.rb test/test-diff.rb Modified: lib/groonga-schema/column.rb (+8 -0) =================================================================== --- lib/groonga-schema/column.rb 2016-08-09 18:39:44 +0900 (f11fba8) +++ lib/groonga-schema/column.rb 2016-08-15 12:06:50 +0900 (8161ab2) @@ -67,6 +67,14 @@ module GroongaSchema Groonga::Command::ColumnCreate.new(arguments) end + def to_remove_groonga_command + arguments = { + "table" => @table_name, + "name" => @name, + } + Groonga::Command::ColumnRemove.new(arguments) + end + private def type_flag case @type Modified: lib/groonga-schema/diff.rb (+35 -0) =================================================================== --- lib/groonga-schema/diff.rb 2016-08-09 18:39:44 +0900 (2a09540) +++ lib/groonga-schema/diff.rb 2016-08-15 12:06:50 +0900 (365c89c) @@ -80,6 +80,7 @@ module GroongaSchema convert_added_plugins convert_added_tables + convert_removed_columns convert_removed_plugins meaningful_grouped_list = @grouped_list.reject do |group| @@ -141,6 +142,40 @@ module GroongaSchema group end + def convert_removed_columns + sorted_removed_columns =****@diff*****_columns.sort_by do |table_name,| + table_name + end + + column_groups = [] + sorted_removed_columns.each do |table_name, columns| + group = [] + columns.each do |column_name, column| + group << column unless column.sources.empty? + end + next if group.empty? + column_groups << group + end + sorted_removed_columns.each do |table_name, columns| + group = [] + columns.each do |column_name, column| + group << column if column.sources.empty? + end + next if group.empty? + column_groups << group + end + + column_groups.each do |columns| + sorted_columns = columns.sort_by do |column| + column.name + end + group = sorted_columns.collect do |column| + column.to_remove_groonga_command + end + @grouped_list << group + end + end + def convert_removed_plugins sorted_plugins =****@diff*****_plugins.sort_by(&:name) @grouped_list << sorted_plugins.collect(&:to_unregister_groonga_command) Modified: test/test-diff.rb (+36 -0) =================================================================== --- test/test-diff.rb 2016-08-09 18:39:44 +0900 (2be9000) +++ test/test-diff.rb 2016-08-15 12:06:50 +0900 (98d5ded) @@ -174,5 +174,41 @@ column_create \\ --type "Commands" LIST end + + test "removed tables" do + @diff.removed_columns["Words"] = { + "weight" => column("Words", "weight", + :value_type => "Float"), + "commands_description" => column("Words", "commands_description", + :type => :index, + :flags => ["WITH_POSITION"], + :value_type => "Commands", + :sources => ["description"], + :reference_value_type => true), + } + @diff.removed_columns["Commands"] = { + "description" => column("Commands", "description", + :value_type => "Text"), + "comment" => column("Commands", "comment", + :value_type => "ShortText"), + } + + assert_equal(<<-LIST.gsub(/\\\n\s+/, ""), @diff.to_groonga_command_list) +column_remove \\ + --name "commands_description" \\ + --table "Words" + +column_remove \\ + --name "comment" \\ + --table "Commands" +column_remove \\ + --name "description" \\ + --table "Commands" + +column_remove \\ + --name "weight" \\ + --table "Words" + LIST + end end end -------------- next part -------------- HTML����������������������������... 다운로드