[Groonga-commit] ranguba/groonga-client-model at 33771ff [master] migration: support geo points

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Mar 6 13:04:19 JST 2017


Kouhei Sutou	2017-03-06 13:04:19 +0900 (Mon, 06 Mar 2017)

  New Revision: 33771ffff10928a332b454991f88737bbb830da9
  https://github.com/ranguba/groonga-client-model/commit/33771ffff10928a332b454991f88737bbb830da9

  Message:
    migration: support geo points

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

  Modified: lib/groonga_client_model/migration.rb (+24 -0)
===================================================================
--- lib/groonga_client_model/migration.rb    2017-03-06 12:56:41 +0900 (a49b777)
+++ lib/groonga_client_model/migration.rb    2017-03-06 13:04:19 +0900 (8be8aaa)
@@ -360,6 +360,30 @@ module GroongaClientModel
         @migration.add_column(@table_name, column_name, :long_text, options)
       end
 
+      def geo_point(column_name, options={})
+        options = options.dup
+        datum = options.delete(:datum) || :wgs84
+        case datum
+        when :wgs84
+          type = "WGS84GeoPoint"
+        when :tokyo
+          type = "TokyoGeoPoint"
+        else
+          message = "invalid geodetic datum: "
+          message << "available: [:wgs84, :tokyo]: #{datum.inspect}"
+          raise ArgumentError, message
+        end
+        @migration.add_column(@table_name, column_name, type, options)
+      end
+
+      def wgs84_geo_point(column_name, options={})
+        geo_point(column_name, options.merge(datum: :wgs84))
+      end
+
+      def tokyo_geo_point(column_name, options={})
+        geo_point(column_name, options.merge(datum: :tokyo))
+      end
+
       def index(source_table_name, source_column_names, options={})
         source_column_names = Array(source_column_names)
         column_name = [source_table_name, *source_column_names].join("_")

  Modified: test/unit/migration/test_create_table.rb (+33 -1)
===================================================================
--- test/unit/migration/test_create_table.rb    2017-03-06 12:56:41 +0900 (0fb3af6)
+++ test/unit/migration/test_create_table.rb    2017-03-06 13:04:19 +0900 (d79db13)
@@ -167,7 +167,7 @@ column_create posts #{column_name} COLUMN_SCALAR #{groonga_type}
         end
       end
 
-      test("#bool alias") do
+      test("alias: #bool") do
         assert_migrate_add_column(:published, "Bool") do |table|
           table.bool(:published)
         end
@@ -270,6 +270,38 @@ column_create posts #{column_name} COLUMN_SCALAR #{groonga_type}
       end
     end
 
+    sub_test_case("#geo_point") do
+      test("default") do
+        assert_migrate_add_column(:location, "WGS84GeoPoint") do |table|
+          table.geo_point(:location)
+        end
+      end
+
+      test("datum: :wgs84") do
+        assert_migrate_add_column(:location, "WGS84GeoPoint") do |table|
+          table.geo_point(:location, datum: :wgs84)
+        end
+      end
+
+      test("datum: :tokyo") do
+        assert_migrate_add_column(:location, "TokyoGeoPoint") do |table|
+          table.geo_point(:location, datum: :tokyo)
+        end
+      end
+
+      test("alias: #wgs84_geo_point") do
+        assert_migrate_add_column(:location, "WGS84GeoPoint") do |table|
+          table.wgs84_geo_point(:location)
+        end
+      end
+
+      test("alias: #tokyo_geo_point") do
+        assert_migrate_add_column(:location, "TokyoGeoPoint") do |table|
+          table.tokyo_geo_point(:location)
+        end
+      end
+    end
+
     sub_test_case("#index") do
       test("for full text search") do
         expected_up_report = <<-REPORT
-------------- next part --------------
HTML����������������������������...
Download 



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