activerecord-postgis-adapter 0.3.1 → 0.3.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.
- data/History.rdoc +5 -0
- data/README.rdoc +39 -13
- data/Version +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter/databases.rake +41 -11
- metadata +4 -22
data/History.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
=== 0.3.2 / 2011-02-11
|
2
|
+
|
3
|
+
* You can now specify a separate "database creation" superuser so your normal postgres user doesn't need superuser privileges when running database creation tasks.
|
4
|
+
* Database creation tasks automatically create all schemas listed in the schema search path.
|
5
|
+
|
1
6
|
=== 0.3.1 / 2011-02-01
|
2
7
|
|
3
8
|
* Fixed a syntax error that prevented the adapter from loading on Ruby 1.8. Whoops. (Reported by miguelperez)
|
data/README.rdoc
CHANGED
@@ -137,30 +137,38 @@ the above require command should appear after <tt>require 'rails/all'</tt>.
|
|
137
137
|
|
138
138
|
Besides the adapter name "postgis", most of the other database connection
|
139
139
|
configuration parameters are the same as for the stock postgresql adapter.
|
140
|
-
However, there are
|
140
|
+
However, there are several important differences:
|
141
141
|
|
142
142
|
The <i>script_dir</i> parameter is specific to the PostGIS adapter, and
|
143
143
|
provides the path to the directory containing the SQL scripts for PostGIS
|
144
144
|
installation. This directory should contain the files <tt>postgis.sql</tt>
|
145
145
|
and <tt>spatial_ref_sys.sql</tt>. (A common setting for this directory
|
146
|
-
might be <tt>/usr/local/share/contrib/postgis-1.5</tt>.) It is used by
|
147
|
-
db:create
|
148
|
-
newly created database. If you do not provide this parameter, you will
|
146
|
+
might be <tt>/usr/local/share/contrib/postgis-1.5</tt>.) It is used by
|
147
|
+
<tt>rake db:create</tt> to add the PostGIS types, functions, and tables to
|
148
|
+
a newly created database. If you do not provide this parameter, you will
|
149
149
|
need to add these objects to the database manually.
|
150
150
|
Generally, therefore, this parameter is required at least for the test
|
151
151
|
database, which is usually automatically created by the rake tasks.
|
152
152
|
|
153
|
-
|
154
|
-
|
153
|
+
The <i>su_username</i> and <i>su_password</i> parameters are provided as
|
154
|
+
optional parameters. If present, they specify an auxiliary Postgres role
|
155
|
+
that will be used for two functions:
|
156
|
+
|
157
|
+
* Creation of the database. This is so the main database user that you
|
158
|
+
specify doesn't need superuser or createdb privileges.
|
159
|
+
* Installation of the PostGIS definitions, if requested by the presence
|
160
|
+
of <i>script_dir</i>. This process normally requires a Postgres role
|
161
|
+
with superuser privileges, so again if you don't want your main database
|
162
|
+
user to have superuser, you can perform this one-time procedure using
|
163
|
+
this alternate user.
|
155
164
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
* Dumping the structure as sql will omit objects in the "postgis" schema.
|
160
|
-
This is often useful if you don't want all the PostGIS definitions
|
161
|
-
cluttering up your SQL dump.
|
165
|
+
Any schemas listed in the <i>schema_search_path</i> parameter are
|
166
|
+
automatically created by <tt>rake db:create</tt>. This is arguably what
|
167
|
+
the stock PostgreSQL adapter should be doing anyway.
|
162
168
|
|
163
|
-
|
169
|
+
If the schema name "postgis" is included in the <i>schema_search_path</i>
|
170
|
+
parameter, the PostGIS adapter omits it from a SQL structure dump. This
|
171
|
+
can be useful to prevent PostGIS definitions from appearing in the dump
|
164
172
|
as described below.
|
165
173
|
|
166
174
|
=== Dealing With PostGIS Definitions
|
@@ -190,6 +198,15 @@ To deal with these issues, we recommend the following technique:
|
|
190
198
|
The PostGIS Adapter responds to this special name by sandboxing the
|
191
199
|
PostGIS definitions into it when rake db:create is run, and it omits
|
192
200
|
this schema when running SQL structure dumps.
|
201
|
+
* Provide a separate <i>su_username</i> and <i>su_password</i> user for
|
202
|
+
your database, and make sure that Postgres user has SUPERUSER
|
203
|
+
privilege. This will cause the PostGIS Adapter to log in as that user
|
204
|
+
when creating the database, since the PostGIS definition installation
|
205
|
+
requires SUPERUSER. Alternately, you can give the normal database user
|
206
|
+
SUPERUSER privilege, which may be okay for a private development
|
207
|
+
database. These are used only by <tt>rake db:create</tt> so you can
|
208
|
+
remove them from your database.yml for your staging or production
|
209
|
+
databases once you've performed the initial creation.
|
193
210
|
|
194
211
|
Finally, you generally should _not_ set the \ActiveRecord schema format
|
195
212
|
to <tt>:sql</tt>. You should leave it set to <tt>:ruby</tt>. The reason
|
@@ -200,10 +217,19 @@ other issues. Instead, the schema.rb output by the Ruby schema format
|
|
200
217
|
should properly replicate the schema. This is a known issue that we are
|
201
218
|
investigating.
|
202
219
|
|
220
|
+
Of course, the above steps are only really necessary if you are using the
|
221
|
+
\ActiveRecord rake tasks that create databases, either directly such as
|
222
|
+
<tt>rake db:create</tt>, or indirectly such as <tt>rake test</tt>. They
|
223
|
+
should not be necessary for running migrations or normal website execution.
|
224
|
+
|
203
225
|
== Additional Information
|
204
226
|
|
205
227
|
=== Known bugs and limitations
|
206
228
|
|
229
|
+
The PostGIS Adapter has not yet been tested in a large variety of
|
230
|
+
environments, and we are still fixing bugs. Here is a partial list of
|
231
|
+
current known issues.
|
232
|
+
|
207
233
|
* Dumping as SQL (i.e. rake db:structure:dump) does not properly emit
|
208
234
|
<tt>AddGeometryColumn</tt> calls, and so does not completely create the
|
209
235
|
spatial schema (e.g. it fails to add the proper row to the
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -47,20 +47,50 @@ def create_database(config_)
|
|
47
47
|
if config_['adapter'] == 'postgis'
|
48
48
|
@encoding = config_['encoding'] || ::ENV['CHARSET'] || 'utf8'
|
49
49
|
begin
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
has_su_ = config_.include?('su_username') # Is there a distinct superuser?
|
51
|
+
username_ = config_['username'] # regular user name
|
52
|
+
su_username_ = config_['su_username'] || username_ # superuser name
|
53
|
+
su_password_ = config_['su_password'] || config_['password'] # superuser password
|
54
|
+
|
55
|
+
# Create the database. Optionally do so as the given superuser.
|
56
|
+
# But make sure the database is owned by the regular user.
|
57
|
+
::ActiveRecord::Base.establish_connection(config_.merge('database' => 'postgres', 'schema_search_path' => 'public', 'username' => su_username_, 'password' => su_password_))
|
58
|
+
extra_configs_ = {'encoding' => @encoding}
|
59
|
+
extra_configs_['owner'] = username_ if has_su_
|
60
|
+
::ActiveRecord::Base.connection.create_database(config_['database'], config_.merge(extra_configs_))
|
61
|
+
|
62
|
+
# Initial setup of the database: Add schemas from the search path.
|
63
|
+
# If a superuser is given, we log in as the superuser, but we make sure
|
64
|
+
# the schemas are owned by the regular user.
|
65
|
+
::ActiveRecord::Base.establish_connection(config_.merge('schema_search_path' => 'public', 'username' => su_username_, 'password' => su_password_))
|
66
|
+
conn_ = ::ActiveRecord::Base.connection
|
67
|
+
search_path_ = config_["schema_search_path"].to_s.strip
|
68
|
+
search_path_ = search_path_.split(",").map{ |sp_| sp_.strip }
|
69
|
+
auth_ = has_su_ ? " AUTHORIZATION #{username_}" : ''
|
70
|
+
search_path_.each do |schema_|
|
71
|
+
conn_.execute("CREATE SCHEMA #{schema_}#{auth_}") unless schema_.downcase == 'public'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Define the postgis stuff, if the script_dir is provided.
|
75
|
+
# Note: a superuser is required to run the postgis definitions.
|
76
|
+
# If a separate superuser is provided, we need to grant privileges on
|
77
|
+
# the postgis definitions over to the regular user afterwards.
|
78
|
+
# The schema for the postgis definitions is chosen as follows:
|
79
|
+
# If "postgis" is present in the search path, use it.
|
80
|
+
# Otherwise, use the last schema in the search path.
|
81
|
+
# If no search path is given, use "public".
|
53
82
|
if (script_dir_ = config_['script_dir'])
|
54
|
-
|
55
|
-
|
56
|
-
search_path_ = search_path_.split(",").map{ |sp_| sp_.strip }
|
57
|
-
if search_path_.include?('postgis')
|
58
|
-
conn_.execute('CREATE SCHEMA postgis')
|
59
|
-
conn_.execute('SET search_path TO postgis')
|
60
|
-
end
|
83
|
+
postgis_schema_ = search_path_.include?('postgis') ? 'postgis' : (search_path_.last || 'public')
|
84
|
+
conn_.execute("SET search_path TO #{postgis_schema_}")
|
61
85
|
conn_.execute(::File.read(::File.expand_path('postgis.sql', script_dir_)))
|
62
86
|
conn_.execute(::File.read(::File.expand_path('spatial_ref_sys.sql', script_dir_)))
|
87
|
+
if has_su_
|
88
|
+
conn_.execute("GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA #{postgis_schema_} TO #{username_}")
|
89
|
+
conn_.execute("GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA #{postgis_schema_} TO #{username_}")
|
90
|
+
end
|
63
91
|
end
|
92
|
+
|
93
|
+
# Done
|
64
94
|
::ActiveRecord::Base.establish_connection(config_)
|
65
95
|
rescue ::Exception => e_
|
66
96
|
$stderr.puts(e_, *(e_.backtrace))
|
@@ -74,7 +104,7 @@ end
|
|
74
104
|
|
75
105
|
def drop_database(config_)
|
76
106
|
if config_['adapter'] == 'postgis'
|
77
|
-
::ActiveRecord::Base.establish_connection(config_.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
107
|
+
::ActiveRecord::Base.establish_connection(config_.merge('database' => 'postgres', 'schema_search_path' => 'public', 'username' => config_['su_username'] || config_['username'], 'password' => config_['su_password'] || config_['password']))
|
78
108
|
::ActiveRecord::Base.connection.drop_database(config_['database'])
|
79
109
|
else
|
80
110
|
drop_database_without_postgis(config_)
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 1
|
9
|
-
version: 0.3.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Daniel Azuma
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-10 00:00:00 -08:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,10 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ~>
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 3
|
31
|
-
- 0
|
32
24
|
version: 0.3.0
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
@@ -40,10 +32,6 @@ dependencies:
|
|
40
32
|
requirements:
|
41
33
|
- - ">="
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
- 10
|
46
|
-
- 0
|
47
35
|
version: 0.10.0
|
48
36
|
type: :runtime
|
49
37
|
version_requirements: *id002
|
@@ -86,23 +74,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
74
|
requirements:
|
87
75
|
- - ">="
|
88
76
|
- !ruby/object:Gem::Version
|
89
|
-
segments:
|
90
|
-
- 1
|
91
|
-
- 8
|
92
|
-
- 7
|
93
77
|
version: 1.8.7
|
94
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
79
|
none: false
|
96
80
|
requirements:
|
97
81
|
- - ">="
|
98
82
|
- !ruby/object:Gem::Version
|
99
|
-
segments:
|
100
|
-
- 0
|
101
83
|
version: "0"
|
102
84
|
requirements: []
|
103
85
|
|
104
86
|
rubyforge_project: virtuoso
|
105
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.5.2
|
106
88
|
signing_key:
|
107
89
|
specification_version: 3
|
108
90
|
summary: An ActiveRecord adapter for PostGIS, based on RGeo.
|