activerecord-postgis-adapter 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/postgis_adapter/arel_tosql.rb +4 -4
- data/lib/active_record/connection_adapters/postgis_adapter/postgis_database_tasks.rb +32 -16
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +1 -1
- data/test/tasks_test.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76d9431bb3c7e39d5fbd758bb5a5235c5bdf2679
|
4
|
+
data.tar.gz: 00b2d3a6e72cd2c66b93de93a4a50f9d011fdba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
#
|
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
|
-
#
|
36
|
+
# Override to use su_username and su_password
|
37
37
|
def establish_master_connection
|
38
38
|
establish_connection(configuration.merge(
|
39
|
-
'database'
|
39
|
+
'database' => 'postgres',
|
40
|
+
'password' => su_password,
|
40
41
|
'schema_search_path' => 'public',
|
41
|
-
'username'
|
42
|
-
|
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'
|
49
|
-
|
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
|
-
|
84
|
-
case
|
85
|
+
extensions = configuration['postgis_extension']
|
86
|
+
case extensions
|
85
87
|
when ::String
|
86
|
-
|
88
|
+
extensions.split(',')
|
87
89
|
when ::Array
|
88
|
-
|
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
|
-
|
98
|
-
|
99
|
-
if ::File.readable?(
|
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
|
-
|
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)
|
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.
|
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:
|
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.
|
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.
|