[Groonga-commit] ranguba/groonga-client-model at 699d89e [master] migration: support custom index name

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Mar 7 21:36:14 JST 2017


Kouhei Sutou	2017-03-07 21:36:14 +0900 (Tue, 07 Mar 2017)

  New Revision: 699d89ecd170e9633ca3a73078d6e5185148ffb6
  https://github.com/ranguba/groonga-client-model/commit/699d89ecd170e9633ca3a73078d6e5185148ffb6

  Message:
    migration: support custom index name

  Modified files:
    lib/groonga_client_model/migration.rb
    test/unit/migration/test_create_table.rb

  Modified: lib/groonga_client_model/migration.rb (+3 -1)
===================================================================
--- lib/groonga_client_model/migration.rb    2017-03-07 20:41:43 +0900 (317da96)
+++ lib/groonga_client_model/migration.rb    2017-03-07 21:36:14 +0900 (851ea6a)
@@ -467,8 +467,10 @@ module GroongaClientModel
       end
 
       def index(source_table_name, source_column_names, options={})
+        options = options.dup
         source_column_names = Array(source_column_names)
-        column_name = [source_table_name, *source_column_names].join("_")
+        column_name = options.delete(:name)
+        column_name ||= [source_table_name, *source_column_names].join("_")
         @migration.add_column(@table_name,
                               column_name,
                               source_table_name,

  Modified: test/unit/migration/test_create_table.rb (+41 -0)
===================================================================
--- test/unit/migration/test_create_table.rb    2017-03-07 20:41:43 +0900 (1d08eee)
+++ test/unit/migration/test_create_table.rb    2017-03-07 21:36:14 +0900 (ac542cc)
@@ -482,6 +482,47 @@ column_create terms posts_title_content COLUMN_INDEX|WITH_SECTION|WITH_POSITION
           end
         end
       end
+
+      test("custom name") do
+        expected_up_report = <<-REPORT
+-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
+   -> 0.0s
+-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"Text"})
+   -> 0.0s
+-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :tokenizer=>"TokenBigram", :normalizer=>"NormalizerAuto"})
+   -> 0.0s
+-- add_column(:terms, :posts, {:flags=>["COLUMN_INDEX", "WITH_POSITION"], :value_type=>:posts, :sources=>[:content]})
+   -> 0.0s
+        REPORT
+        expected_down_report = <<-REPORT
+-- remove_table(:terms)
+   -> 0.0s
+-- remove_table(:posts)
+   -> 0.0s
+        REPORT
+        expected_dump = <<-DUMP.chomp
+table_create posts TABLE_NO_KEY
+column_create posts content COLUMN_SCALAR Text
+
+table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
+
+column_create terms posts COLUMN_INDEX|WITH_POSITION posts content
+        DUMP
+        assert_migrate(expected_up_report,
+                       expected_down_report,
+                       expected_dump) do |migration|
+          migration.instance_eval do
+            create_table(:posts) do |table|
+              table.text(:content)
+            end
+
+            create_table(:terms,
+                         :propose => :full_text_search) do |table|
+              table.index(:posts, [:content], name: :posts)
+            end
+          end
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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