activerecord-postgis-adapter 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d2bd161f205308afbc558cdd1b78a3895fa6d57
4
- data.tar.gz: 9d8012bd9863180566481fa062582d15a0b093a4
3
+ metadata.gz: 2ff4e3a14420f0cb54ab5f2ee745eb9b48a5cfc5
4
+ data.tar.gz: 51adb18e9a0b6f5678863e8ac480b5910868f82f
5
5
  SHA512:
6
- metadata.gz: 2f791f644fedb57ec26b2c2adc6cdcca315246f6ad51b2e2f6e056eb612d3b2f88305e0ba99836b70dc59d8b76db3febfe64941226dc37d7a9eedde5a9437ae2
7
- data.tar.gz: 061590b4d9fbe64b2cb03c8dab47263ed91c4d980683fd366a055675a106c715d10691c846008afeab03aaffb2d64286357510e4f2af909e050bb09b981ad6fc
6
+ metadata.gz: 44a9ac94f6ee75aebecd789a1b988d88a137663c039b0a187f8653abc22992e5641c5804c64db414a19fdaacec7322bb2c0900f6b15442194259a33034529d16
7
+ data.tar.gz: 2bc25c45236615f6a782d22046b15185881f14395a1ab437a0e45b5f1f8672ad871242c211914f455136740feb74422b1d1b25c9aaf4bc1b932b150d6e5a0c23
@@ -27,28 +27,27 @@ module ActiveRecord # :nodoc:
27
27
  end
28
28
  end
29
29
 
30
+ # FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS
31
+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
30
32
  def columns(table_name, name = nil)
31
- # FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS.
32
- # We needed to return a spatial column subclass.
33
- table_name = table_name.to_s
33
+ # Limit, precision, and scale are all handled by the superclass.
34
34
  spatial_info_ = spatial_column_info(table_name)
35
- column_definitions(table_name).collect do |col_name, type, default, notnull, oid, fmod|
36
- oid = column_type_map.fetch(oid.to_i, fmod.to_i) {
37
- OID::Identity.new
38
- }
35
+ column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod|
36
+ oid = column_type_map.fetch(oid.to_i, fmod.to_i) { OID::Identity.new }
39
37
  SpatialColumn.new(@rgeo_factory_settings,
40
38
  table_name,
41
- col_name,
39
+ column_name,
42
40
  default,
43
41
  oid,
44
42
  type,
45
43
  notnull == 'f',
46
- type =~ /geometry/i ? spatial_info_[col_name] : nil)
44
+ type =~ /geometry/i ? spatial_info_[column_name] : nil)
47
45
  end
48
46
  end
49
47
 
48
+ # FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS
49
+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
50
50
  def indexes(table_name, name = nil)
51
- # FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS.
52
51
  result = query(<<-SQL, 'SCHEMA')
53
52
  SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid
54
53
  FROM pg_class t
@@ -62,7 +61,7 @@ module ActiveRecord # :nodoc:
62
61
  SQL
63
62
 
64
63
  result.map do |row|
65
- index_name_ = row[0]
64
+ index_name = row[0]
66
65
  unique = row[1] == 't'
67
66
  indkey = row[2].split(" ")
68
67
  inddef = row[3]
@@ -78,17 +77,19 @@ module ActiveRecord # :nodoc:
78
77
  columns = columns.inject({}){ |h, r| h[r[0].to_s] = [r[1], r[2]]; h }
79
78
  column_names = columns.values_at(*indkey).compact.map{ |a| a[0] }
80
79
 
81
- # add info on sort order for columns (only desc order is explicitly specified, asc is the default)
82
- desc_order_columns_ = inddef.scan(/(\w+) DESC/).flatten
83
- orders = desc_order_columns_.any? ? Hash[desc_order_columns_.map {|order_column_| [order_column_, :desc]}] : {}
84
- where = inddef.scan(/WHERE (.+)$/).flatten[0]
85
- spatial = inddef =~ /using\s+gist/i && columns.size == 1 &&
86
- (columns.values.first[1] == 'geometry' || columns.values.first[1] == 'geography')
80
+ unless column_names.empty?
81
+ # add info on sort order for columns (only desc order is explicitly specified, asc is the default)
82
+ desc_order_columns = inddef.scan(/(\w+) DESC/).flatten
83
+ orders = desc_order_columns.any? ? Hash[desc_order_columns.map {|order_column| [order_column, :desc]}] : {}
84
+ where = inddef.scan(/WHERE (.+)$/).flatten[0]
85
+ # using = inddef.scan(/USING (.+?) /).flatten[0].to_sym
87
86
 
88
- if column_names.empty?
89
- nil
90
- else
91
- ::RGeo::ActiveRecord::SpatialIndexDefinition.new(table_name, index_name_, unique, column_names, [], orders, where, !!spatial)
87
+ spatial = inddef =~ /using\s+gist/i &&
88
+ columns.size == 1 &&
89
+ %w[geometry geography].include?(columns.values.first[1])
90
+
91
+ # IndexDefinition.new(table_name, index_name, unique, column_names, [], orders, where, nil, using)
92
+ ::RGeo::ActiveRecord::SpatialIndexDefinition.new(table_name, index_name, unique, column_names, [], orders, where, !!spatial)
92
93
  end
93
94
  end.compact
94
95
  end
@@ -168,13 +169,15 @@ module ActiveRecord # :nodoc:
168
169
  end
169
170
  end
170
171
 
172
+ # FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS
173
+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
171
174
  def add_index(table_name, column_name, options = {})
172
- # FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS.
173
175
  # We have to fully-replace because of the gist_clause.
174
- options ||= {}
175
- gist_clause = options.delete(:spatial) ? ' USING GIST' : ''
176
- index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, options)
177
- execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)}#{gist_clause} (#{index_columns})#{index_options}"
176
+
177
+ gist = options.delete(:spatial)
178
+ index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, options)
179
+ index_using = 'USING GIST' if gist
180
+ execute "CREATE #{index_type} INDEX #{index_algorithm} #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} #{index_using} (#{index_columns})#{index_options}"
178
181
  end
179
182
 
180
183
  def spatial_column_info(table_name)
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module PostGISAdapter
4
- VERSION = '2.0.0'.freeze
4
+ VERSION = '2.0.1'.freeze
5
5
  end
6
6
  end
7
7
  end
data/test/database.yml CHANGED
@@ -3,3 +3,4 @@ host: 127.0.0.1
3
3
  database: postgis_adapter_test
4
4
  username: postgres
5
5
  setup: default
6
+ schema_search_path: public
data/test/tasks_test.rb CHANGED
@@ -28,80 +28,109 @@ module RGeo
28
28
  define_test_methods do
29
29
  def test_create_database_from_extension_in_public_schema
30
30
  ::ActiveRecord::Tasks::DatabaseTasks.create(TasksTest.new_database_config)
31
- ::ActiveRecord::Base.connection.select_values("SELECT * from public.spatial_ref_sys")
31
+ refute_empty connection.select_values("SELECT * from public.spatial_ref_sys")
32
32
  end
33
33
 
34
34
  def test_empty_sql_dump
35
- filename = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
36
- ::FileUtils.rm_f(filename)
37
- ::FileUtils.mkdir_p(::File.dirname(filename))
38
- ::ActiveRecord::Tasks::DatabaseTasks.create(TasksTest.new_database_config.merge('schema_search_path' => 'public'))
39
- ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, filename)
40
- sql = ::File.read(filename)
35
+ setup_database_tasks
36
+ ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
37
+ sql = ::File.read(tmp_sql_filename)
41
38
  assert(sql !~ /CREATE TABLE/)
42
39
  end
43
40
 
44
41
  def test_basic_geography_sql_dump
45
- filename = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
46
- ::FileUtils.rm_f(filename)
47
- ::FileUtils.mkdir_p(::File.dirname(filename))
48
- ::ActiveRecord::Tasks::DatabaseTasks.create(TasksTest.new_database_config.merge('schema_search_path' => 'public'))
49
- ::ActiveRecord::Base.connection.create_table(:spatial_test) do |t|
50
- t.point "latlon", :geographic => true
42
+ setup_database_tasks
43
+ connection.create_table(:spatial_test) do |t|
44
+ t.point "latlon", geographic: true
51
45
  end
52
- ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, filename)
53
- data = ::File.read(filename)
46
+ ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
47
+ data = ::File.read(tmp_sql_filename)
54
48
  assert(data.index('latlon geography(Point,4326)'))
55
49
  end
56
50
 
51
+ def test_index_sql_dump
52
+ setup_database_tasks
53
+ connection.create_table(:spatial_test) do |t|
54
+ t.point "latlon", geographic: true
55
+ t.string "name"
56
+ end
57
+ connection.add_index :spatial_test, :latlon, spatial: true
58
+ connection.add_index :spatial_test, :name, using: :btree
59
+ ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
60
+ data = ::File.read(tmp_sql_filename)
61
+ assert(data.index('latlon geography(Point,4326)'))
62
+ assert data.index('CREATE INDEX index_spatial_test_on_latlon ON spatial_test USING gist (latlon);')
63
+ assert data.index('CREATE INDEX index_spatial_test_on_name ON spatial_test USING btree (name);')
64
+ end
65
+
57
66
  def test_empty_schema_dump
58
- filename = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
59
- ::FileUtils.rm_f(filename)
60
- ::FileUtils.mkdir_p(::File.dirname(filename))
61
- ::ActiveRecord::Tasks::DatabaseTasks.create(TasksTest.new_database_config.merge('schema_search_path' => 'public'))
62
- ::File.open(filename, "w:utf-8") do |file|
67
+ setup_database_tasks
68
+ ::File.open(tmp_sql_filename, "w:utf-8") do |file|
63
69
  ::ActiveRecord::SchemaDumper.dump(::ActiveRecord::Base.connection, file)
64
70
  end
65
- data = ::File.read(filename)
71
+ data = ::File.read(tmp_sql_filename)
66
72
  assert(data.index('ActiveRecord::Schema'))
67
73
  end
68
74
 
69
75
  def test_basic_geometry_schema_dump
70
- filename = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
71
- ::FileUtils.rm_f(filename)
72
- ::FileUtils.mkdir_p(::File.dirname(filename))
73
- ::ActiveRecord::Tasks::DatabaseTasks.create(TasksTest.new_database_config.merge('schema_search_path' => 'public'))
74
- conn = ::ActiveRecord::Base.connection
75
- conn.create_table(:spatial_test) do |t|
76
+ setup_database_tasks
77
+ connection.create_table(:spatial_test) do |t|
76
78
  t.geometry 'object1'
77
- t.spatial "object2", :limit => {:srid=>conn.default_srid, :type=>"geometry"}
79
+ t.spatial "object2", limit: { srid: connection.default_srid, type: "geometry" }
78
80
  end
79
- ::File.open(filename, "w:utf-8") do |file|
80
- ::ActiveRecord::SchemaDumper.dump(conn, file)
81
+ ::File.open(tmp_sql_filename, "w:utf-8") do |file|
82
+ ::ActiveRecord::SchemaDumper.dump(connection, file)
81
83
  end
82
- data = ::File.read(filename)
83
- assert(data.index("t.spatial \"object1\", limit: {:srid=>#{conn.default_srid}, :type=>\"geometry\"}"))
84
- assert(data.index("t.spatial \"object2\", limit: {:srid=>#{conn.default_srid}, :type=>\"geometry\"}"))
84
+ data = ::File.read(tmp_sql_filename)
85
+ assert(data.index("t.spatial \"object1\", limit: {:srid=>#{connection.default_srid}, :type=>\"geometry\"}"))
86
+ assert(data.index("t.spatial \"object2\", limit: {:srid=>#{connection.default_srid}, :type=>\"geometry\"}"))
85
87
  end
86
88
 
87
89
  def test_basic_geography_schema_dump
88
- filename = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
89
- ::FileUtils.rm_f(filename)
90
- ::FileUtils.mkdir_p(::File.dirname(filename))
91
- ::ActiveRecord::Tasks::DatabaseTasks.create(TasksTest.new_database_config.merge('schema_search_path' => 'public'))
92
- conn = ::ActiveRecord::Base.connection
93
- conn.create_table(:spatial_test) do |t|
94
- t.point "latlon1", :geographic => true
95
- t.spatial "latlon2", :limit => {:srid=>4326, :type=>"point", :geographic=>true}
90
+ setup_database_tasks
91
+ connection.create_table(:spatial_test) do |t|
92
+ t.point "latlon1", geographic: true
93
+ t.spatial "latlon2", limit: { srid: 4326, type: "point", geographic: true }
96
94
  end
97
- ::File.open(filename, "w:utf-8") do |file|
98
- ::ActiveRecord::SchemaDumper.dump(conn, file)
95
+ ::File.open(tmp_sql_filename, "w:utf-8") do |file|
96
+ ::ActiveRecord::SchemaDumper.dump(connection, file)
99
97
  end
100
- data = ::File.read(filename)
98
+ data = ::File.read(tmp_sql_filename)
101
99
  assert(data.index('t.spatial "latlon1", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
102
100
  assert(data.index('t.spatial "latlon2", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
103
101
  end
102
+
103
+ def test_index_schema_dump
104
+ setup_database_tasks
105
+ connection.create_table(:spatial_test) do |t|
106
+ t.point "latlon", geographic: true
107
+ end
108
+ connection.add_index :spatial_test, :latlon, spatial: true
109
+ ::File.open(tmp_sql_filename, "w:utf-8") do |file|
110
+ ::ActiveRecord::SchemaDumper.dump(connection, file)
111
+ end
112
+ data = ::File.read(tmp_sql_filename)
113
+ assert data.index('t.spatial "latlon", limit: {:srid=>4326, :type=>"point", :geographic=>true}')
114
+ assert data.index('add_index "spatial_test", ["latlon"], :name => "index_spatial_test_on_latlon", :spatial => true')
115
+ end
104
116
  end
117
+
118
+ private
119
+
120
+ def connection
121
+ ::ActiveRecord::Base.connection
122
+ end
123
+
124
+ def tmp_sql_filename
125
+ ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
126
+ end
127
+
128
+ def setup_database_tasks
129
+ ::FileUtils.rm_f(tmp_sql_filename)
130
+ ::FileUtils.mkdir_p(::File.dirname(tmp_sql_filename))
131
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TasksTest.new_database_config)
132
+ end
133
+
105
134
  end
106
135
  end
107
136
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma, Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord