pgbundle 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pgbundle +7 -0
- data/lib/pgbundle/database.rb +2 -0
- data/lib/pgbundle/definition.rb +8 -0
- data/lib/pgbundle/extension.rb +49 -15
- data/lib/pgbundle/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c92283e7b0cdc9239828c2e0b0c4c0f0de445f8
|
4
|
+
data.tar.gz: d17777f703f2296061e87d11e8dc1f91f5915d9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb211cac9c484da384c3e70cff5125060fd5e548839ebdb4673f42f4305a4c50b3d7dc22181c21a1b55a50ceec1d3624d58de8dc107114e459ed26f71bb7e387
|
7
|
+
data.tar.gz: ad84fbf4ce4985c9fb6be3b8b363068e16930df7b83c83f505cb0d686581e2785d7f4239c62cd7938fab6fe31cffc35dce4fd6841875aa501a165b54b274f041
|
data/bin/pgbundle
CHANGED
@@ -44,6 +44,13 @@ module PgBundle
|
|
44
44
|
exit 1 if missing
|
45
45
|
end
|
46
46
|
|
47
|
+
desc 'create', 'create the extension at the desired version'
|
48
|
+
def create(pgfile = 'Pgfile')
|
49
|
+
definition(pgfile).create.each do | d |
|
50
|
+
say_status('created', d.name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
47
54
|
desc 'init', 'write an initial pgfile to stdout'
|
48
55
|
method_options %w( user -u ) => :string
|
49
56
|
method_options %w( host -h ) => :string
|
data/lib/pgbundle/database.rb
CHANGED
data/lib/pgbundle/definition.rb
CHANGED
@@ -40,6 +40,14 @@ module PgBundle
|
|
40
40
|
installed.select { |dep| dep.available?(database) }
|
41
41
|
end
|
42
42
|
|
43
|
+
# create all required extensions
|
44
|
+
def create
|
45
|
+
extensions.map do |_, dep|
|
46
|
+
dep.create_with_dependencies(database)
|
47
|
+
dep
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
43
51
|
def init
|
44
52
|
["database '#{database.name}', host: '#{database.host}', user: #{database.user}, system_user: #{database.system_user}, use_sudo: #{database.use_sudo}"] +
|
45
53
|
database.current_definition.map do |r|
|
data/lib/pgbundle/extension.rb
CHANGED
@@ -65,11 +65,11 @@ module PgBundle
|
|
65
65
|
end
|
66
66
|
|
67
67
|
# returns true if extension is already created with the correct version in the given database
|
68
|
-
def created?(
|
68
|
+
def created?(database_or_connection)
|
69
69
|
if version
|
70
|
-
result =
|
70
|
+
result = database_or_connection.exec("SELECT * FROM pg_available_extension_versions WHERE name ='#{name}' AND version = '#{version}' AND installed").to_a
|
71
71
|
else
|
72
|
-
result =
|
72
|
+
result = database_or_connection.exec("SELECT * FROM pg_available_extension_versions WHERE name ='#{name}' AND installed").to_a
|
73
73
|
end
|
74
74
|
|
75
75
|
if result.empty?
|
@@ -81,11 +81,11 @@ module PgBundle
|
|
81
81
|
|
82
82
|
# returns if the extension is already installed on the database system
|
83
83
|
# if it is also already created it returns the installed version
|
84
|
-
def installed?(
|
84
|
+
def installed?(database_or_connection)
|
85
85
|
if version
|
86
|
-
result =
|
86
|
+
result = database_or_connection.exec("SELECT * FROM pg_available_extension_versions WHERE name ='#{name}' AND version = '#{version}'").to_a
|
87
87
|
else
|
88
|
-
result =
|
88
|
+
result = database_or_connection.exec("SELECT * FROM pg_available_extension_versions WHERE name ='#{name}'").to_a
|
89
89
|
end
|
90
90
|
|
91
91
|
if result.empty?
|
@@ -123,11 +123,22 @@ module PgBundle
|
|
123
123
|
make_uninstall(database)
|
124
124
|
end
|
125
125
|
|
126
|
-
|
126
|
+
# create the extension along with it's dependencies in a transaction
|
127
|
+
def create_with_dependencies(database)
|
128
|
+
return true if created?(database)
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
database.transaction do |con|
|
131
|
+
begin
|
132
|
+
create_dependencies(con)
|
133
|
+
create_or_update!(con)
|
134
|
+
rescue PG::UndefinedFile => err
|
135
|
+
raise ExtensionNotFound.new(name, version)
|
136
|
+
rescue PG::UndefinedObject => err
|
137
|
+
raise MissingDependency.new(name, err.message)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
true
|
131
142
|
end
|
132
143
|
|
133
144
|
# create the dependency graph on the given connection
|
@@ -136,14 +147,31 @@ module PgBundle
|
|
136
147
|
dependencies.each do |_, d|
|
137
148
|
fail CircularDependencyError.new(name, d.name) if d.resolving_dependencies
|
138
149
|
d.create_dependencies(con)
|
139
|
-
d.
|
150
|
+
d.create_or_update!(con)
|
140
151
|
end
|
141
152
|
@resolving_dependencies = false
|
142
153
|
end
|
143
154
|
|
155
|
+
# create extension on a given database connection
|
156
|
+
def create!(con)
|
157
|
+
con.exec create_stmt
|
158
|
+
end
|
159
|
+
|
160
|
+
def create_or_update!(con)
|
161
|
+
return true if created?(con)
|
162
|
+
if created_any_version?(con)
|
163
|
+
con.exec update_stmt
|
164
|
+
else
|
165
|
+
create!(con)
|
166
|
+
end
|
167
|
+
true
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
|
144
172
|
# checks if Extension is already installed at any version thus need ALTER EXTENSION to install
|
145
|
-
def created_any_version?(
|
146
|
-
result =
|
173
|
+
def created_any_version?(database_or_connection)
|
174
|
+
result = database_or_connection.exec("SELECT * FROM pg_available_extension_versions WHERE name ='#{name}' AND installed").to_a
|
147
175
|
if result.empty?
|
148
176
|
false
|
149
177
|
else
|
@@ -151,6 +179,8 @@ module PgBundle
|
|
151
179
|
end
|
152
180
|
end
|
153
181
|
|
182
|
+
private
|
183
|
+
|
154
184
|
# adds dependencies that are required but not defined yet
|
155
185
|
def add_missing_required_dependencies(database)
|
156
186
|
requires = requires(database)
|
@@ -199,7 +229,7 @@ module PgBundle
|
|
199
229
|
# loads the source and runs make install
|
200
230
|
# returns: self
|
201
231
|
def make_install(database, force = false)
|
202
|
-
return self if installed?(database) && !force
|
232
|
+
return self if installed?(database) && (!force || source.nil?)
|
203
233
|
|
204
234
|
fail SourceNotFound, name if source.nil?
|
205
235
|
|
@@ -214,6 +244,10 @@ module PgBundle
|
|
214
244
|
stmt
|
215
245
|
end
|
216
246
|
|
247
|
+
def update_stmt
|
248
|
+
"ALTER EXTENSION #{name} UPDATE TO '#{version}'"
|
249
|
+
end
|
250
|
+
|
217
251
|
def install_dependencies(database, force = false)
|
218
252
|
begin
|
219
253
|
dependencies.each do |_, d|
|
@@ -251,7 +285,7 @@ module PgBundle
|
|
251
285
|
result = true
|
252
286
|
database.execute 'BEGIN'
|
253
287
|
begin
|
254
|
-
database.execute
|
288
|
+
database.execute update_stmt
|
255
289
|
rescue PG::UndefinedFile, PG::UndefinedObject => err
|
256
290
|
@error = err.message
|
257
291
|
result = false
|
data/lib/pgbundle/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgbundle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Kniep
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.2.
|
188
|
+
rubygems_version: 2.2.2
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: bundling postgres extension
|