prodder 1.7.2 → 1.7.3

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: 7018f84da517a86834a557666183b7a8fd81d9b3
4
- data.tar.gz: 33a7fe098859ec975862a8413f29a38cf3a4a8e1
3
+ metadata.gz: 46d073f63217c538b5ec9fa2a83c668548f95673
4
+ data.tar.gz: e1e81386094c8c7054c2bea7228db0bd345ea385
5
5
  SHA512:
6
- metadata.gz: c05ab47457496eeabdbcbe792dacd9069b5c1ef8d1f3c21ddc5bf81e460e9648994f6c2e5aa0352aac7ce1faba642acb0a7794844a7465f6c9670020e6eb4f27
7
- data.tar.gz: 9258441141b1ec6f90052bf898c99735ad2cb9e2e7be3d334baa5ef1e9b4406b648554275196fd192736f91218184d0c26d064dccc9bfd4435e3b0a89fdb99b3
6
+ metadata.gz: d6f9275cf746c5dcfd50e05e5c1d21eaabbfe8316e5107f358e38fd62f52e1b070accf1dcc9d9bcc119768883804ebc8b6c4add17172d31c71a3010aec7e7076
7
+ data.tar.gz: 81bf60f578179fdb3a39011826a0ed4bbcc84c24c6294ef82f193e3115c9bb086b6d8aaa1600f87931377c820c0004714622ae9380220f3813416994c0c51c2a
@@ -18,7 +18,7 @@ before_install:
18
18
  # install postgresql v9.5
19
19
  - if [[ "$PG_VERSION" = "9.5" ]]; then echo "installing pg9.5"; sudo /etc/init.d/postgresql stop; sudo apt-get -y autoremove; sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 7FCC7D46ACCC4CF8; sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main 9.5" >> /etc/apt/sources.list.d/postgresql.list'; sudo apt-get update; sudo apt-get -y install postgresql-9.5; sudo cp /etc/postgresql/9.4/main/pg_hba.conf /etc/postgresql/9.5/main/pg_hba.conf; sudo sed -i 's/5433/5432/' /etc/postgresql/9.5/main/postgresql.conf; sudo /etc/init.d/postgresql restart; else echo "not installing pg9.5"; fi
20
20
  # setup travis user
21
- - if [[ "$PG_VERSION" = "9.5" ]]; then echo "setting up users for pg9.5"; PGUSER=postgres createuser --superuser travis || true; fi
21
+ - if [[ "$PG_VERSION" = "9.5" ]]; then echo "setting up users for pg9.5"; PGUSER=postgres createuser --superuser travis || echo role travis already exists.; fi
22
22
  # setup pg_dump
23
23
  - sudo ln -sfn /usr/lib/postgresql/$PG_VERSION/bin/pg_dump /usr/bin/pg_dump
24
24
  # start up the specific version of PG
@@ -42,8 +42,8 @@ module Prodder
42
42
  end
43
43
 
44
44
  def dump_settings(db_name, filename)
45
- sql = <<-SQL
46
- select unnest(setconfig)
45
+ db_settings = pg_conn(db_name) { |conn| conn.exec(<<-SQL).map { |setting| setting['config'] } }
46
+ select unnest(setconfig) as config
47
47
  from pg_catalog.pg_db_role_setting
48
48
  join pg_database on pg_database.oid = setdatabase
49
49
  -- 0 = default, for all users
@@ -51,24 +51,19 @@ module Prodder
51
51
  and datname = '#{db_name}'
52
52
  SQL
53
53
 
54
- arguments = [
55
- '--host', credentials['host'],
56
- '--username', credentials['user'],
57
- '-t',
58
- '-c', sql
59
- ]
60
-
61
- run ['psql', *arguments.push(db_name)] do |out, err, success|
62
- raise PGDumpError.new(err) if !success
63
- File.open(filename, 'w') do |f|
64
- out.each_line do |setting|
65
- setting.gsub!(/\s+/, '')
66
- unless setting.empty?
67
- setting.chomp!
68
- setting += "''" if setting.match(/=$/)
69
- # using the magic of psql variables through :DBNAME
70
- f.puts "ALTER DATABASE :DBNAME SET #{setting};"
71
- end
54
+ File.open(filename, 'w') do |f|
55
+ db_settings.each do |setting|
56
+ # wipe out all spaces
57
+ setting.gsub!(/\s+/, '')
58
+
59
+ # if the setting is empty, ignore it
60
+ unless setting.empty?
61
+ # else, drop carriage returns/new lines
62
+ setting.chomp!
63
+ # and append an empty string if the setting was being assigned a value of nothing
64
+ setting += "''" if setting.match(/=$/)
65
+ # using the magic of psql variables through :DBNAME
66
+ f.puts "ALTER DATABASE :DBNAME SET #{setting};"
72
67
  end
73
68
  end
74
69
  end
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  module Prodder
2
4
  # The list of default rake tasks which prodder will be removing or replacing.
3
5
  # @see databases.rake (currently at lib/active_record/railties/databases.rake)
@@ -169,6 +171,7 @@ namespace :db do
169
171
  ActiveRecord::Tasks::DatabaseTasks.create_current
170
172
  ActiveRecord::Base.configurations.each do |env, config|
171
173
  if environments.include?(env) && config["migration_user"] && config['database']
174
+ set_psql_env config
172
175
  `psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}`
173
176
  end
174
177
  end
@@ -181,6 +184,7 @@ namespace :db do
181
184
  ActiveRecord::Tasks::DatabaseTasks.create_all
182
185
  ActiveRecord::Base.configurations.each do |env, config|
183
186
  if config["migration_user"] && config['database']
187
+ set_psql_env config
184
188
  `psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}`
185
189
  end
186
190
  end
@@ -210,71 +214,77 @@ namespace :db do
210
214
 
211
215
  desc "Load initial seeds from db/seeds.sql"
212
216
  task :seed => dependencies do
213
- if File.exist?('db/seeds.sql')
214
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
215
- config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql')
216
- set_psql_env config
217
- puts "Loading db/seeds.sql into database '#{config['database']}'"
218
- `psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}`
219
- raise 'Error loading db/seeds.sql' if $?.exitstatus != 0
220
- else
217
+ unless File.exist?('db/seeds.sql')
221
218
  puts 'db/seeds.sql not found: no seeds to load.'
219
+ return
222
220
  end
221
+
222
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
223
+ config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql')
224
+ set_psql_env config
225
+ puts "Loading db/seeds.sql into database '#{config['database']}'"
226
+ `psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}`
227
+ raise 'Error loading db/seeds.sql' if $?.exitstatus != 0
223
228
  end
224
229
 
225
230
  desc "Load quality_checks (indexes, triggers, foreign keys) from db/quality_checks.sql"
226
231
  task :quality_check => dependencies do
227
- if File.exist?('db/quality_checks.sql')
228
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
229
- config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql')
230
- set_psql_env config
231
- puts "Loading db/quality_checks.sql into database '#{config['database']}'"
232
- `psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}`
233
- raise 'Error loading db/quality_checks.sql' if $?.exitstatus != 0
234
- else
232
+ unless File.exist?('db/quality_checks.sql')
235
233
  puts 'db/quality_checks.sql not found: no quality_checks to load.'
234
+ return
236
235
  end
236
+
237
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
238
+ config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql')
239
+ set_psql_env config
240
+ puts "Loading db/quality_checks.sql into database '#{config['database']}'"
241
+ `psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}`
242
+ raise 'Error loading db/quality_checks.sql' if $?.exitstatus != 0
237
243
  end
238
244
 
239
245
  desc "Load permissions (DB object level access control, group role memberships) from db/permissions.sql"
240
246
  task :permission => dependencies do
241
- if File.exist?('db/permissions.sql')
242
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
243
- config["username"] = config["superuser"] if config["superuser"]
244
- set_psql_env config
245
- puts "Loading db/permissions.sql into database '#{config['database']}'"
246
- disconnect
247
- ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern)
248
- is_super = ActiveRecord::Base.connection.execute(<<-SQL).first['is_super']
249
- select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
250
- SQL
251
- unless is_super
252
- puts "Restoring permissions as config/database.yml non-superuser: #{config['username']}, expect errors, or rerun after granting superuser"
253
- end
254
- `psql --no-psqlrc -f db/permissions.sql #{Shellwords.escape(config['database'])}`
255
-
256
- raise 'Error loading db/permissions.sql' if $?.exitstatus != 0
257
- else
247
+ unless File.exist?('db/permissions.sql')
258
248
  puts 'db/permissions.sql not found: no permissions to load.'
249
+ return
259
250
  end
251
+
252
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
253
+ config["username"] = config["superuser"] if config["superuser"]
254
+ set_psql_env config
255
+ puts "Loading db/permissions.sql into database '#{config['database']}'"
256
+ disconnect
257
+ ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern)
258
+ result = ActiveRecord::Base.connection.execute(<<-SQL).first
259
+ select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
260
+ SQL
261
+ unless result && result['is_super']
262
+ puts "Restoring permissions as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser"
263
+ end
264
+ `psql --no-psqlrc -f db/permissions.sql #{Shellwords.escape(config['database'])}`
265
+ raise 'Error loading db/permissions.sql' if $?.exitstatus != 0
260
266
  end
261
267
 
262
268
  desc "Load database settings"
263
269
  task :settings => dependencies do
270
+ unless File.exist?('db/settings.sql')
271
+ puts 'db/settings.sql not found: no settings to load.'
272
+ return
273
+ end
274
+
264
275
  config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
265
276
  config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql')
266
277
  set_psql_env config
267
278
  puts "Loading db/settings.sql into database '#{config['database']}'"
268
279
  disconnect
269
280
  ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern)
270
- is_super = ActiveRecord::Base.connection.execute(<<-SQL).first['is_super']
281
+ result = ActiveRecord::Base.connection.execute(<<-SQL).first
271
282
  select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
272
283
  SQL
273
- unless is_super
274
- puts "Restoring settings as config/database.yml non-superuser: #{config['username']}, expect errors, or rerun after granting superuser"
284
+ unless result && result['is_super']
285
+ puts "Restoring settings as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser"
275
286
  end
276
287
  `psql --no-psqlrc -f db/settings.sql #{Shellwords.escape(config['database'])}`
277
-
278
288
  raise 'Error loading db/settings.sql' if $?.exitstatus != 0
279
289
  end
280
290
 
@@ -1,3 +1,3 @@
1
1
  module Prodder
2
- VERSION = "1.7.2"
2
+ VERSION = "1.7.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prodder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Hargraves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-17 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deject