[Groonga-commit] groonga/groonga-schema at 8152206 [master] differ: support changing tables

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Aug 8 13:19:31 JST 2016


Kouhei Sutou	2016-08-08 13:19:31 +0900 (Mon, 08 Aug 2016)

  New Revision: 81522063b33f9da6273fb751ca2dba69a0cf29c8
  https://github.com/groonga/groonga-schema/commit/81522063b33f9da6273fb751ca2dba69a0cf29c8

  Message:
    differ: support changing tables

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

  Modified: lib/groonga-schema/diff.rb (+6 -6)
===================================================================
--- lib/groonga-schema/diff.rb    2016-08-08 13:11:30 +0900 (4267046)
+++ lib/groonga-schema/diff.rb    2016-08-08 13:19:31 +0900 (78dbc56)
@@ -21,22 +21,22 @@ module GroongaSchema
 
     attr_reader :removed_tables
     attr_reader :added_tables
-    attr_reader :renamed_tables
+    attr_reader :changed_tables
 
     attr_reader :removed_columns
     attr_reader :added_columns
-    attr_reader :renamed_columns
+    attr_reader :changed_columns
     def initialize
       @removed_plugins = []
       @added_plugins = []
 
       @removed_tables = {}
       @added_tables = {}
-      @renamed_tables = {}
+      @changed_tables = {}
 
       @removed_columns = {}
       @added_columns = {}
-      @renamed_columns = {}
+      @changed_columns = {}
     end
 
     def ==(other)
@@ -46,10 +46,10 @@ module GroongaSchema
         @added_plugins == other.added_plugins and
         @removed_tables == other.removed_tables and
         @added_tables == other.added_tables and
-        @renamed_tables == other.renamed_tables and
+        @changed_tables == other.changed_tables and
         @removed_columns == other.removed_columns and
         @added_columns == other.added_columns and
-        @renamed_columns == other.renamed_columns
+        @changed_columns == other.changed_columns
     end
   end
 end

  Modified: lib/groonga-schema/differ.rb (+2 -0)
===================================================================
--- lib/groonga-schema/differ.rb    2016-08-08 13:11:30 +0900 (44bea8b)
+++ lib/groonga-schema/differ.rb    2016-08-08 13:19:31 +0900 (4b08abc)
@@ -47,6 +47,8 @@ module GroongaSchema
         to_table = to_tables[name]
         if to_table.nil?
           diff.removed_tables[name] = from_table
+        elsif from_table != to_table
+          diff.changed_tables[name] = to_table
         end
       end
 

  Modified: lib/groonga-schema/table.rb (+13 -0)
===================================================================
--- lib/groonga-schema/table.rb    2016-08-08 13:11:30 +0900 (41cb720)
+++ lib/groonga-schema/table.rb    2016-08-08 13:19:31 +0900 (0a8fa98)
@@ -40,6 +40,19 @@ module GroongaSchema
       applier.apply
     end
 
+    def ==(other)
+      return false unless other.is_a?(self.class)
+
+      @name == other.name and
+        @type == other.type and
+        @flags.sort == other.flags.sort and
+        @key_type == other.key_type and
+        @value_type == other.value_type and
+        @default_tokenizer == other.default_tokenizer and
+        @normalizer == other.normalizer and
+        @token_filters == other.token_filters
+    end
+
     class CommandApplier
       def initialize(table, command)
         @table = table

  Modified: test/test-differ.rb (+20 -4)
===================================================================
--- test/test-differ.rb    2016-08-08 13:11:30 +0900 (fd2be3e)
+++ test/test-differ.rb    2016-08-08 13:19:31 +0900 (cce47d3)
@@ -39,8 +39,7 @@ class DifferTest < Test::Unit::TestCase
         "normalizer"        => "NormalizerAuto",
         "token_filters"     => "TokenStem|TokenStopWord",
       }
-      command = table_create(arguments)
-      @to.apply_command(command)
+      @to.apply_command(table_create(arguments))
 
       actual = GroongaSchema::Diff.new
       actual.added_tables["Words"] =****@to*****["Words"]
@@ -56,12 +55,29 @@ class DifferTest < Test::Unit::TestCase
         "normalizer"        => "NormalizerAuto",
         "token_filters"     => "TokenStem|TokenStopWord",
       }
-      command = table_create(arguments)
-      @from.apply_command(command)
+      @from.apply_command(table_create(arguments))
 
       actual = GroongaSchema::Diff.new
       actual.removed_tables["Words"] =****@from*****["Words"]
       assert_equal(actual, @differ.diff)
     end
+
+    test "table - change" do
+      from_arguments = {
+        "name"              => "Words",
+        "flags"             => "TABLE_PAT_KEY",
+        "key_type"          => "ShortText",
+        "default_tokenizer" => "TokenBigram",
+        "normalizer"        => "NormalizerAuto",
+        "token_filters"     => "TokenStem|TokenStopWord",
+      }
+      to_arguments = from_arguments.merge("default_tokenizer" => "TokenMecab")
+      @from.apply_command(table_create(from_arguments))
+      @to.apply_command(table_create(to_arguments))
+
+      actual = GroongaSchema::Diff.new
+      actual.changed_tables["Words"] =****@to*****["Words"]
+      assert_equal(actual, @differ.diff)
+    end
   end
 end

  Modified: test/test-table.rb (+35 -0)
===================================================================
--- test/test-table.rb    2016-08-08 13:11:30 +0900 (bba4445)
+++ test/test-table.rb    2016-08-08 13:19:31 +0900 (9b4a2d1)
@@ -54,4 +54,39 @@ class TableTest < Test::Unit::TestCase
                    })
     end
   end
+
+  sub_test_case "#==" do
+    test "equal" do
+      arguments = {
+        "name"              => "Words",
+        "flags"             => "TABLE_PAT_KEY",
+        "key_type"          => "ShortText",
+        "default_tokenizer" => "TokenBigram",
+        "normalizer"        => "NormalizerAuto",
+        "token_filters"     => "TokenStem|TokenStopWord",
+      }
+      command = table_create(arguments)
+      table1 = GroongaSchema::Table.new("Words")
+      table1.apply_command(command)
+      table2 = GroongaSchema::Table.new("Words")
+      table2.apply_command(command)
+      assert_equal(table1, table2)
+    end
+
+    test "not equal" do
+      arguments = {
+        "name"              => "Words",
+        "flags"             => "TABLE_PAT_KEY",
+        "key_type"          => "ShortText",
+        "default_tokenizer" => "TokenBigram",
+        "normalizer"        => "NormalizerAuto",
+        "token_filters"     => "TokenStem|TokenStopWord",
+      }
+      table1 = GroongaSchema::Table.new("Words1")
+      table1.apply_command(table_create(arguments.merge("name" => "Words1")))
+      table2 = GroongaSchema::Table.new("Words2")
+      table2.apply_command(table_create(arguments.merge("name" => "Words2")))
+      assert_not_equal(table1, table2)
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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