activerecord-postgis-adapter 2.2.1 → 2.2.2

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: b52208ecdfd87beec772fa39025cce50cd04c01d
4
- data.tar.gz: ea574e93f4e76a74f1e7a97e5dddc892e176e179
3
+ metadata.gz: 76d9431bb3c7e39d5fbd758bb5a5235c5bdf2679
4
+ data.tar.gz: 00b2d3a6e72cd2c66b93de93a4a50f9d011fdba1
5
5
  SHA512:
6
- metadata.gz: fcc4c8a0aba03cd3b9e5f0ceeec9a0c39ae3be10faa2eb571e5280ad59b6e97d83245c76cb749bd9d11a6f135e26edb60f39c6456f8f06246e3484de78e8735a
7
- data.tar.gz: 1ab978f2b167f0480f971863040ba235e868e70a60cc2efe0ba74f176fd7e2339649d63c1069059e87dea9e52e5bb8f88d908e4b82d3981c1a6e22ef6f3cc653
6
+ metadata.gz: 96a805abbd12a4d90038b7896198c12370214881fba6ddd62cee2b062720c575b4f9479e63746fa385363484161c65070be30484cf14d208616c4c1f15aac93f
7
+ data.tar.gz: 64f9df06696a296d146d07323b4cd6b7c11797f756447264262d68fd992f487e9ed0a0f03e4696542356da07add81ffc4d8513ec5615fc844bf72a940c628a8c
@@ -2,10 +2,10 @@ module Arel # :nodoc:
2
2
  module Visitors # :nodoc:
3
3
  # Different super-class under JRuby JDBC adapter.
4
4
  PostGISSuperclass = if defined?(::ArJdbc::PostgreSQL::BindSubstitution)
5
- ::ArJdbc::PostgreSQL::BindSubstitution
6
- else
7
- ::Arel::Visitors::PostgreSQL
8
- end
5
+ ::ArJdbc::PostgreSQL::BindSubstitution
6
+ else
7
+ ::Arel::Visitors::PostgreSQL
8
+ end
9
9
 
10
10
  class PostGIS < PostGISSuperclass # :nodoc:
11
11
 
@@ -16,10 +16,10 @@ module ActiveRecord # :nodoc:
16
16
  establish_connection(configuration)
17
17
  end
18
18
 
19
- # Overridden to set the database owner and call setup_gis
19
+ # Override to set the database owner and call setup_gis
20
20
  def create(master_established = false)
21
21
  establish_master_connection unless master_established
22
- extra_configs = {'encoding' => encoding}
22
+ extra_configs = { 'encoding' => encoding }
23
23
  extra_configs['owner'] = username if has_su?
24
24
  connection.create_database(configuration['database'], configuration.merge(extra_configs))
25
25
  setup_gis
@@ -33,20 +33,22 @@ module ActiveRecord # :nodoc:
33
33
 
34
34
  private
35
35
 
36
- # Overridden to use su_username and su_password
36
+ # Override to use su_username and su_password
37
37
  def establish_master_connection
38
38
  establish_connection(configuration.merge(
39
- 'database' => 'postgres',
39
+ 'database' => 'postgres',
40
+ 'password' => su_password,
40
41
  'schema_search_path' => 'public',
41
- 'username' => su_username,
42
- 'password' => su_password))
42
+ 'username' => su_username,
43
+ ))
43
44
  end
44
45
 
45
46
  def establish_su_connection
46
47
  establish_connection(configuration.merge(
48
+ 'password' => su_password,
47
49
  'schema_search_path' => 'public',
48
- 'username' => su_username,
49
- 'password' => su_password))
50
+ 'username' => su_username,
51
+ ))
50
52
  end
51
53
 
52
54
  def username
@@ -80,12 +82,12 @@ module ActiveRecord # :nodoc:
80
82
 
81
83
  def extension_names
82
84
  @extension_names ||= begin
83
- ext_ = configuration['postgis_extension']
84
- case ext_
85
+ extensions = configuration['postgis_extension']
86
+ case extensions
85
87
  when ::String
86
- ext_.split(',')
88
+ extensions.split(',')
87
89
  when ::Array
88
- ext_
90
+ extensions
89
91
  else
90
92
  ['postgis']
91
93
  end
@@ -94,9 +96,9 @@ module ActiveRecord # :nodoc:
94
96
 
95
97
  def ensure_installation_configs
96
98
  if configuration['setup'] == 'default' && !configuration['postgis_extension']
97
- share_dir_ = `pg_config --sharedir`.strip rescue '/usr/share'
98
- control_file_ = ::File.expand_path('extension/postgis.control', share_dir_)
99
- if ::File.readable?(control_file_)
99
+ share_dir = `pg_config --sharedir`.strip rescue '/usr/share'
100
+ control_file = ::File.expand_path('extension/postgis.control', share_dir)
101
+ if ::File.readable?(control_file)
100
102
  configuration['postgis_extension'] = 'postgis'
101
103
  end
102
104
  end
@@ -108,10 +110,24 @@ module ActiveRecord # :nodoc:
108
110
  raise ::ArgumentError, "'topology' must be in schema_search_path for postgis_topology" unless search_path.include?('topology')
109
111
  connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} SCHEMA topology")
110
112
  else
111
- connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname}")
113
+ if (postgis_schema = configuration['postgis_schema'])
114
+ schema_clause = "WITH SCHEMA #{postgis_schema}"
115
+ unless schema_exists?(postgis_schema)
116
+ connection.execute("CREATE SCHEMA #{postgis_schema}")
117
+ connection.execute("GRANT ALL ON SCHEMA #{postgis_schema} TO PUBLIC")
118
+ end
119
+ else
120
+ schema_clause = ''
121
+ end
122
+
123
+ connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} #{schema_clause}")
112
124
  end
113
125
  end
114
126
  end
127
+
128
+ def schema_exists?(schema_name)
129
+ connection.execute("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '#{schema_name}'").any?
130
+ end
115
131
  end
116
132
 
117
133
  ::ActiveRecord::Tasks::DatabaseTasks.register_task(/postgis/, PostGISDatabaseTasks)
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module PostGISAdapter
4
- VERSION = '2.2.1'.freeze
4
+ VERSION = '2.2.2'.freeze
5
5
  end
6
6
  end
7
7
  end
data/test/tasks_test.rb CHANGED
@@ -27,6 +27,12 @@ class TasksTest < ActiveSupport::TestCase # :nodoc:
27
27
  refute_empty connection.select_values("SELECT * from public.spatial_ref_sys")
28
28
  end
29
29
 
30
+ def test_create_database_from_extension_in_separate_schema
31
+ configuration = TasksTest.new_database_config.merge('postgis_schema' => 'postgis')
32
+ ::ActiveRecord::Tasks::DatabaseTasks.create(configuration)
33
+ refute_empty connection.select_values("SELECT * from postgis.spatial_ref_sys")
34
+ end
35
+
30
36
  def test_empty_sql_dump
31
37
  setup_database_tasks
32
38
  ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
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.2.1
4
+ version: 2.2.2
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-09-23 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.4.1
142
+ rubygems_version: 2.4.6
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: ActiveRecord adapter for PostGIS, based on RGeo.