[Groonga-commit] groonga/groonga-schema at 5f9ac67 [master] Support outputting removed tables

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Aug 15 12:20:44 JST 2016


Kouhei Sutou	2016-08-15 12:20:44 +0900 (Mon, 15 Aug 2016)

  New Revision: 5f9ac67091bc7e0ea329c57b16b06d678ebb78cc
  https://github.com/groonga/groonga-schema/commit/5f9ac67091bc7e0ea329c57b16b06d678ebb78cc

  Message:
    Support outputting removed tables

  Modified files:
    lib/groonga-schema/diff.rb
    lib/groonga-schema/table.rb
    test/test-diff.rb

  Modified: lib/groonga-schema/diff.rb (+14 -0)
===================================================================
--- lib/groonga-schema/diff.rb    2016-08-15 12:06:50 +0900 (365c89c)
+++ lib/groonga-schema/diff.rb    2016-08-15 12:20:44 +0900 (682b0aa)
@@ -81,6 +81,7 @@ module GroongaSchema
         convert_added_plugins
         convert_added_tables
         convert_removed_columns
+        convert_removed_tables
         convert_removed_plugins
 
         meaningful_grouped_list = @grouped_list.reject do |group|
@@ -176,6 +177,19 @@ module GroongaSchema
         end
       end
 
+      def convert_removed_tables
+        sorted_tables =****@diff*****_tables.sort_by do |name, table|
+          [
+            table.reference_key_type? ? 0 : 1,
+            table.name,
+          ]
+        end
+
+        sorted_tables.each do |name, table|
+          @grouped_list << [table.to_remove_groonga_command]
+        end
+      end
+
       def convert_removed_plugins
         sorted_plugins =****@diff*****_plugins.sort_by(&:name)
         @grouped_list << sorted_plugins.collect(&:to_unregister_groonga_command)

  Modified: lib/groonga-schema/table.rb (+7 -0)
===================================================================
--- lib/groonga-schema/table.rb    2016-08-15 12:06:50 +0900 (0500943)
+++ lib/groonga-schema/table.rb    2016-08-15 12:20:44 +0900 (71dd8fa)
@@ -75,6 +75,13 @@ module GroongaSchema
       Groonga::Command::TableCreate.new(arguments)
     end
 
+    def to_remove_groonga_command
+      arguments = {
+        "name" => @name,
+      }
+      Groonga::Command::TableRemove.new(arguments)
+    end
+
     private
     def type_flag
       case @type

  Modified: test/test-diff.rb (+21 -1)
===================================================================
--- test/test-diff.rb    2016-08-15 12:06:50 +0900 (98d5ded)
+++ test/test-diff.rb    2016-08-15 12:20:44 +0900 (16cfa4e)
@@ -175,7 +175,7 @@ column_create \\
       LIST
     end
 
-    test "removed tables" do
+    test "removed columns" do
       @diff.removed_columns["Words"] = {
         "weight" => column("Words", "weight",
                            :value_type => "Float"),
@@ -210,5 +210,25 @@ column_remove \\
   --table "Words"
       LIST
     end
+
+    test "removed tables" do
+      @diff.removed_tables["Names"] = table("Names",
+                                            :type => :hash_key,
+                                            :flags => "KEY_LARGE",
+                                            :key_type => "ShortText",
+                                            :normalizer => "NormalizerAuto")
+      @diff.removed_tables["Commands"] = table("Commands",
+                                               :type => :hash_key,
+                                               :key_type => "Names",
+                                               :reference_key_type => true)
+
+      assert_equal(<<-LIST.gsub(/\\\n\s+/, ""), @diff.to_groonga_command_list)
+table_remove \\
+  --name "Commands"
+
+table_remove \\
+  --name "Names"
+      LIST
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index