prodder 1.7.2 → 1.7.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7018f84da517a86834a557666183b7a8fd81d9b3
4
- data.tar.gz: 33a7fe098859ec975862a8413f29a38cf3a4a8e1
2
+ SHA256:
3
+ metadata.gz: 837adeb9529887b429bbe128bbb9162f29d0ca5001fbd94b28aba2aa105caacb
4
+ data.tar.gz: e3b410b12794de3b1a04d55adad8ac789c83658526c4a749b8494878381c7e0a
5
5
  SHA512:
6
- metadata.gz: c05ab47457496eeabdbcbe792dacd9069b5c1ef8d1f3c21ddc5bf81e460e9648994f6c2e5aa0352aac7ce1faba642acb0a7794844a7465f6c9670020e6eb4f27
7
- data.tar.gz: 9258441141b1ec6f90052bf898c99735ad2cb9e2e7be3d334baa5ef1e9b4406b648554275196fd192736f91218184d0c26d064dccc9bfd4435e3b0a89fdb99b3
6
+ metadata.gz: d5982600241c08dc3c623c8c1e6153cfbd10bd6c20f3fa3074f4cf45335f6fd091c58e31e2e26da624c956b6624458ce21ce117568b933ec72aab8f2f30d295d
7
+ data.tar.gz: 697799d716ab1bd9a7fbc19b3a346681621ffd8cf3b732ee2eed41acb86b7626fb0eb16f239a307c62c797f890a1cfc9c8e2d6db367fb1542ed174ca14512aee
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ Gemfile.lock
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -2,24 +2,20 @@ language: ruby
2
2
  cache: bundler
3
3
 
4
4
  rvm:
5
- - 2.3.0
6
- - 2.2.4
7
- - 2.1.8
5
+ - 2.5.8
6
+ - 2.7.2
8
7
 
9
8
  env:
10
9
  matrix:
11
- - PG_VERSION=9.3
12
- - PG_VERSION=9.4
13
- - PG_VERSION=9.5
10
+ - PG_VERSION=11
14
11
 
15
12
  before_install:
16
13
  - git config --global user.name "Prodder In Travis-CI"
17
14
  - git config --global user.email "prodder@example.com"
18
- # install postgresql v9.5
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
- # setup travis user
21
- - if [[ "$PG_VERSION" = "9.5" ]]; then echo "setting up users for pg9.5"; PGUSER=postgres createuser --superuser travis || true; fi
15
+ # install postgres
16
+ - sudo apt-get install postgresql-client-$PG_VERSION postgresql-server-dev-$PG_VERSION
22
17
  # setup pg_dump
18
+ - ls -al /usr/lib/postgresql/
23
19
  - sudo ln -sfn /usr/lib/postgresql/$PG_VERSION/bin/pg_dump /usr/bin/pg_dump
24
20
  # start up the specific version of PG
25
21
  - sudo -E sh -c 'service postgresql stop'
@@ -28,17 +24,10 @@ before_install:
28
24
  - psql -U postgres -d postgres -c 'select setting from pg_settings where name = $m$server_version$m$;'
29
25
 
30
26
  script:
31
- - echo "===================================================="
32
- - echo "PG_VERSION|$PG_VERSION|"
33
- - echo "===================================================="
34
27
  - psql --version
35
- - echo "===================================================="
36
28
  - pg_lsclusters
37
- - echo "===================================================="
38
29
  - psql -U postgres -d postgres -c 'select 1;'
39
- - echo "===================================================="
40
30
  - ls -al `which pg_dump`
41
- - echo "===================================================="
42
31
  - bundle exec rake spec
43
32
  - bundle exec rake cucumber
44
33
 
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ group :development, :test do
10
10
  gem 'pry'
11
11
  gem 'pry-remote'
12
12
  gem 'rspec'
13
- gem 'cucumber'
14
- gem 'aruba'
13
+ gem 'cucumber', '< 3' # FIXME
14
+ gem 'aruba', '~> 0.5.0'
15
15
  gem 'pg'
16
16
  end
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
  prodder [![Build Status](https://travis-ci.org/enova/prodder.svg?branch=master)](https://travis-ci.org/enova/prodder)
3
3
  =======
4
4
 
5
- A tool to maintain and load your Rails application's database structure and seed
6
- table contents, based on its migration history and the current in production
7
- databases.
5
+ A tool to maintain and load your Rails application's database structure, seed
6
+ table contents, permissions and database settings based on its migration history
7
+ and the current state in production databases.
8
8
 
9
9
  In short: `db:reset db:migrate`
10
10
 
@@ -29,7 +29,7 @@ Feature: Commiting updated dumps to a project's repository
29
29
  And I run `prodder dump -c prodder.yml`
30
30
  And I run `prodder commit -c prodder.yml`
31
31
  And 2 commits by "prodder auto-commit" should be in the "blog" repository
32
- And the latest commit should have changed "db/structure.sql" to contain "CREATE TABLE linkbacks"
32
+ And the latest commit should have changed "db/structure.sql" to contain "CREATE TABLE public.linkbacks"
33
33
  And the latest commit should not have changed "db/seeds.sql"
34
34
  And the latest commit should not have changed "db/quality_checks.sql"
35
35
 
@@ -52,7 +52,7 @@ Feature: Commiting updated dumps to a project's repository
52
52
  And I run `prodder dump -c prodder.yml`
53
53
  And I run `prodder commit -c prodder.yml`
54
54
  Then 2 commits by "prodder auto-commit" should be in the "blog" repository
55
- And the latest commit should have changed "db/structure.sql" to contain "CREATE TABLE captchas"
55
+ And the latest commit should have changed "db/structure.sql" to contain "CREATE TABLE public.captchas"
56
56
  And the latest commit should have changed "db/seeds.sql" to contain "Bob McBobbington"
57
57
  And the latest commit should not have changed "db/quality_checks.sql"
58
58
 
@@ -64,6 +64,6 @@ Feature: Commiting updated dumps to a project's repository
64
64
  And I run `prodder dump -c prodder.yml`
65
65
  And I run `prodder commit -c prodder.yml`
66
66
  And 2 commits by "prodder auto-commit" should be in the "blog" repository
67
- And the latest commit should have changed "db/permissions.sql" to contain "GRANT ALL ON TABLE gotchas TO prodder"
67
+ And the latest commit should have changed "db/permissions.sql" to contain "GRANT ALL ON TABLE public.gotchas TO prodder"
68
68
  And the latest commit should not have changed "db/seeds.sql"
69
69
  And the latest commit should not have changed "db/quality_checks.sql"
@@ -6,11 +6,10 @@ Feature: prodder dump
6
6
  Scenario: Happy path: dump structure.sql, listed seed tables, quality_checks.sql, permissions.sql and settings.sql
7
7
  When I run `prodder dump -c prodder.yml`
8
8
  Then the exit status should be 0
9
- And the workspace file "blog/db/structure.sql" should match /CREATE TABLE posts/
10
- And the workspace file "blog/db/structure.sql" should match /CREATE TABLE authors/
11
- And the workspace file "blog/db/seeds.sql" should match /COPY posts/
12
- And the workspace file "blog/db/seeds.sql" should match /COPY authors/
13
- And the workspace file "blog/db/quality_checks.sql" should match /SET search_path/
9
+ And the workspace file "blog/db/structure.sql" should match /CREATE TABLE public.posts/
10
+ And the workspace file "blog/db/structure.sql" should match /CREATE TABLE public.authors/
11
+ And the workspace file "blog/db/seeds.sql" should match /COPY public.posts/
12
+ And the workspace file "blog/db/seeds.sql" should match /COPY public.authors/
14
13
  And the workspace file "blog/db/quality_checks.sql" should match /CREATE TRIGGER /
15
14
  And the workspace file "blog/db/permissions.sql" should match /GRANT /
16
15
  And the workspace file "blog/db/settings.sql" should match /ALTER DATABASE /
@@ -123,6 +122,7 @@ Feature: prodder dump
123
122
  Given I add a custom parameter "c.p" with value "v" in the "blog" project's database
124
123
  When I run `prodder dump -c prodder.yml`
125
124
  Then the workspace file "blog/db/settings.sql" should match /ALTER DATABASE :DBNAME SET c.p=v;/
125
+ And the workspace file "blog/db/settings.sql" should match /ALTER DATABASE :DBNAME SET search_path=foo,bar,public;/
126
126
 
127
127
  Scenario: Verify empty db setting is quoted
128
128
  Given I add a custom parameter "empty.setting" with value "" in the "blog" project's database
@@ -184,8 +184,8 @@ Feature: prodder dump
184
184
  """
185
185
  When I run `prodder dump -c prodder.yml`
186
186
  Then the exit status should be 0
187
- And the workspace file "blog/db/seeds.sql" should match /COPY posts/
188
- But the workspace file "blog/db/seeds.sql" should not match /COPY authors/
187
+ And the workspace file "blog/db/seeds.sql" should match /COPY public.posts/
188
+ But the workspace file "blog/db/seeds.sql" should not match /COPY public.authors/
189
189
 
190
190
  Scenario: YAML file listing seed tables does not exist
191
191
  Given the prodder config in "prodder.yml" says to read the "blog" seed tables from "db/seeds.yml"
@@ -2,7 +2,7 @@ Feature: Basic CLI usage
2
2
 
3
3
  Scenario: prodder help
4
4
  When I run `prodder help`
5
- Then the output should contain "Tasks:"
5
+ Then the output should contain "Commands:"
6
6
 
7
7
  Scenario: No config file supplied
8
8
  When I run `prodder`
@@ -16,7 +16,7 @@ Feature: prodder push
16
16
  Given the "blog" git repository does not allow pushing to it
17
17
  When I run `prodder push -c prodder.yml`
18
18
  Then the exit status should be 1
19
- And the output should contain "insufficient permission"
19
+ And the output should contain "remote rejected"
20
20
 
21
21
  Scenario: Push fails due to non-fast-forward
22
22
  Given a new commit is already in the "blog" git repository
@@ -5,8 +5,10 @@ Given 'a "$project" git repository' do |project|
5
5
  end
6
6
 
7
7
  run_simple "mkdir -p repos"
8
- run_simple "chmod -R a+w repos/#{project}.git" if File.exist? File.join(current_dir, "repos", "#{project}.git")
9
- remove_dir "repos/#{project}.git"
8
+ if File.exist? File.join(current_dir, "repos", "#{project}.git")
9
+ run_simple "chmod -R a+w repos/#{project}.git"
10
+ run_simple "rm -rf repos/#{project}.git"
11
+ end
10
12
  run_simple "cp -pR #{fixture_repo} repos/#{project}.git"
11
13
  end
12
14
 
@@ -29,37 +31,37 @@ end
29
31
  Then(/^(\d+) commits? by "([^"]+)" should be in the "([^"]+)" repository$/) do |n, author, project|
30
32
  in_workspace(project) do
31
33
  authors = `git log --pretty='format:%an'`.split("\n")
32
- authors.grep(/#{author}/).size.should == Integer(n)
34
+ expect(authors.grep(/#{author}/).size).to eq Integer(n)
33
35
  end
34
36
  end
35
37
 
36
38
  Then 'the file "$filename" should now be tracked' do |filename|
37
39
  in_current_dir do
38
40
  git = Prodder::Git.new(File.expand_path("prodder-workspace/blog"), nil)
39
- git.should be_tracked(filename)
41
+ expect(git).to be_tracked(filename)
40
42
  end
41
43
  end
42
44
 
43
45
  Then 'the latest commit should have changed "$file" to contain "$content"' do |filename, content|
44
46
  in_workspace('blog') do
45
47
  changed = `git show --name-only HEAD | grep #{filename}`.split("\n")
46
- changed.should_not be_empty
48
+ expect(changed).to_not be_empty
47
49
 
48
50
  diff = `git show HEAD | grep '#{content}'`.split("\n")
49
- diff.should_not be_empty
51
+ expect(diff).to_not be_empty
50
52
  end
51
53
  end
52
54
 
53
55
  Then 'the latest commit should not have changed "$filename"' do |filename|
54
56
  in_workspace('blog') do
55
57
  changed = `git show --name-only HEAD | grep #{filename}`.split("\n")
56
- changed.should be_empty
58
+ expect(changed).to be_empty
57
59
  end
58
60
  end
59
61
 
60
62
  Then 'the new commit should be in the remote repository' do
61
63
  in_current_dir do
62
64
  latest = `git --git-dir="./repos/blog.git" log | grep prodder`.split("\n")
63
- latest.should_not be_empty
65
+ expect(latest).to_not be_empty
64
66
  end
65
67
  end
@@ -1,4 +1,5 @@
1
1
  ALTER DATABASE prodder__blog_prod SET custom.parameter = 1;
2
+ ALTER DATABASE prodder__blog_prod SET search_path TO foo, bar, public;
2
3
 
3
4
  CREATE TABLE authors (
4
5
  author_id serial primary key,
@@ -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
@@ -130,7 +125,6 @@ module Prodder
130
125
  ACL_REVOKE = /^REVOKE /
131
126
  DEFAULT_PRIVILEGES = /^ALTER DEFAULT PRIVILEGES /
132
127
  SET_OBJECT_OWNERSHIP = /.* OWNER TO /
133
- SEARCH_PATH = /SET search_path = .*/
134
128
 
135
129
  def dump_db_access_control(db_name, user_list, options)
136
130
  perm_out_sql = ""
@@ -158,8 +152,7 @@ module Prodder
158
152
  if line.match(ACL_GRANT) ||
159
153
  line.match(ACL_REVOKE) ||
160
154
  line.match(DEFAULT_PRIVILEGES) ||
161
- line.match(SET_OBJECT_OWNERSHIP)||
162
- line.match(SEARCH_PATH)
155
+ line.match(SET_OBJECT_OWNERSHIP)
163
156
 
164
157
  unless irrelevant_login_roles.include?(line.match(/ (\S*);$/)[1])
165
158
  perm_out_sql << line
@@ -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)
@@ -96,7 +98,7 @@ namespace :db do
96
98
  begin
97
99
  puts ActiveRecord::Tasks::DatabaseTasks.collation_current
98
100
  rescue NoMethodError
99
- $stderr.puts 'Sorry, your database adapter is not supported yet. Feel free to submit a patch.'
101
+ $stderr.puts 'error: Sorry, your database adapter is not supported yet. Feel free to submit a patch.'
100
102
  end
101
103
  end
102
104
  end
@@ -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
@@ -199,24 +203,26 @@ namespace :db do
199
203
  namespace :structure do
200
204
  desc "Load db/structure.sql into the current environment's database"
201
205
  task :load => dependencies do
202
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
203
- config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql')
204
- set_psql_env config
205
- puts "Loading db/structure.sql into database '#{config['database']}'"
206
- `psql --no-psqlrc -f db/structure.sql #{Shellwords.escape(config['database'])}`
207
- raise 'Error loading db/structure.sql' if $?.exitstatus != 0
206
+ as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
207
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
208
+ set_psql_env config
209
+ puts "Loading db/structure.sql into database '#{config['database']}'"
210
+ `psql --no-psqlrc -f db/structure.sql #{Shellwords.escape(config['database'])}`
211
+ raise 'Error loading db/structure.sql' if $?.exitstatus != 0
212
+ end
208
213
  end
209
214
  end
210
215
 
211
216
  desc "Load initial seeds from db/seeds.sql"
212
217
  task :seed => dependencies do
213
218
  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
219
+ as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
220
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
221
+ set_psql_env config
222
+ puts "Loading db/seeds.sql into database '#{config['database']}'"
223
+ `psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}`
224
+ raise 'Error loading db/seeds.sql' if $?.exitstatus != 0
225
+ end
220
226
  else
221
227
  puts 'db/seeds.sql not found: no seeds to load.'
222
228
  end
@@ -225,12 +231,13 @@ namespace :db do
225
231
  desc "Load quality_checks (indexes, triggers, foreign keys) from db/quality_checks.sql"
226
232
  task :quality_check => dependencies do
227
233
  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
+ as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
235
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
236
+ set_psql_env config
237
+ puts "Loading db/quality_checks.sql into database '#{config['database']}'"
238
+ `psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}`
239
+ raise 'Error loading db/quality_checks.sql' if $?.exitstatus != 0
240
+ end
234
241
  else
235
242
  puts 'db/quality_checks.sql not found: no quality_checks to load.'
236
243
  end
@@ -239,21 +246,19 @@ namespace :db do
239
246
  desc "Load permissions (DB object level access control, group role memberships) from db/permissions.sql"
240
247
  task :permission => dependencies do
241
248
  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"
249
+ as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
250
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
251
+ set_psql_env config
252
+ puts "Loading db/permissions.sql into database '#{config['database']}'"
253
+ result = ActiveRecord::Base.connection.execute(<<-SQL).first
254
+ select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
255
+ SQL
256
+ unless result && result['is_super']
257
+ puts "warning: Restoring permissions as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser"
258
+ end
259
+ `psql --no-psqlrc -f db/permissions.sql #{Shellwords.escape(config['database'])}`
260
+ raise 'Error loading db/permissions.sql' if $?.exitstatus != 0
253
261
  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
262
  else
258
263
  puts 'db/permissions.sql not found: no permissions to load.'
259
264
  end
@@ -261,21 +266,23 @@ namespace :db do
261
266
 
262
267
  desc "Load database settings"
263
268
  task :settings => dependencies do
264
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
265
- config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql')
266
- set_psql_env config
267
- puts "Loading db/settings.sql into database '#{config['database']}'"
268
- disconnect
269
- ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern)
270
- is_super = ActiveRecord::Base.connection.execute(<<-SQL).first['is_super']
271
- select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
272
- SQL
273
- unless is_super
274
- puts "Restoring settings as config/database.yml non-superuser: #{config['username']}, expect errors, or rerun after granting superuser"
269
+ if File.exist?('db/settings.sql')
270
+ as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
271
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
272
+ set_psql_env config
273
+ puts "Loading db/settings.sql into database '#{config['database']}'"
274
+ result = ActiveRecord::Base.connection.execute(<<-SQL).first
275
+ select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
276
+ SQL
277
+ unless result && result['is_super']
278
+ puts "warning: Restoring settings as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser"
279
+ end
280
+ `psql --no-psqlrc -f db/settings.sql #{Shellwords.escape(config['database'])}`
281
+ raise 'Error loading db/settings.sql' if $?.exitstatus != 0
282
+ end
283
+ else
284
+ puts 'db/settings.sql not found: no settings to load.'
275
285
  end
276
- `psql --no-psqlrc -f db/settings.sql #{Shellwords.escape(config['database'])}`
277
-
278
- raise 'Error loading db/settings.sql' if $?.exitstatus != 0
279
286
  end
280
287
 
281
288
  # Empty this, we don't want db:migrate writing structure.sql any more.
@@ -355,7 +362,8 @@ namespace :db do
355
362
 
356
363
  def as(user, opts = {}, &block)
357
364
  if File.exist?('db/permissions.sql')
358
- config, config_was = ActiveRecord::Base.configurations.deep_dup, ActiveRecord::Base.configurations.deep_dup
365
+ # `ActiveRecord::Base.configurations` in Rails 6 now returns an object instead of a hash
366
+ config, config_was = ActiveRecord::Base.configurations.deep_dup.to_h, ActiveRecord::Base.configurations.deep_dup
359
367
  in_env = Array(opts[:in]) || config.keys
360
368
  if config.all? { |env, config_hash| in_env.include?(env) ? config_hash[user] : true }
361
369
  disconnect
@@ -45,9 +45,8 @@ module Prodder
45
45
  contents = File.readlines(structure_file_name)
46
46
  rgx = /^\-\- .* Type: INDEX; |^\-\- .* Type: TRIGGER; |^\-\- .* Type: FK CONSTRAINT; /
47
47
  structure, *quality = contents.slice_before(rgx).to_a
48
- quality_checks = structure.grep(/SET search_path/).last + quality.join
49
48
 
50
- File.open(quality_check_file_name, 'w') { |f| f.write(quality_checks) }
49
+ File.open(quality_check_file_name, 'w') { |f| f.write(quality.join) }
51
50
  File.open(structure_file_name, 'w') { |f| f.write(structure.join) }
52
51
  end
53
52
 
@@ -1,3 +1,3 @@
1
1
  module Prodder
2
- VERSION = "1.7.2"
2
+ VERSION = "1.7.7"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Prodder::Config, 'linting' do
3
+ RSpec.describe Prodder::Config, 'linting' do
4
4
  let(:valid_config) { YAML.load Prodder::Config.example_contents }
5
5
 
6
6
  def config_without(path)
@@ -21,7 +21,6 @@ describe Prodder::Config, 'linting' do
21
21
  end
22
22
 
23
23
  context 'missing required key:' do
24
-
25
24
  %w[structure_file
26
25
  seed_file
27
26
 
@@ -35,15 +34,14 @@ describe Prodder::Config, 'linting' do
35
34
  git/author
36
35
  ].each do |path|
37
36
  specify path do
38
- errors_for(config_without "blog/#{path}").should ==
39
- ["Missing required configuration key: blog/#{path}"]
37
+ expect(errors_for(config_without "blog/#{path}")).to eq ["Missing required configuration key: blog/#{path}"]
40
38
  end
41
39
  end
42
40
  end
43
41
 
44
42
  context 'optional keys:' do
45
43
  specify 'db/password' do
46
- errors_for(config_without 'blog/db/password').should be_empty
44
+ expect(errors_for(config_without 'blog/db/password')).to be_empty
47
45
  end
48
46
  end
49
47
 
@@ -53,12 +51,12 @@ describe Prodder::Config, 'linting' do
53
51
  expect {
54
52
  config.lint!
55
53
  }.to raise_error(Prodder::Config::LintError) { |ex|
56
- ex.errors.should == ['Missing required configuration key: blog/db/name']
54
+ expect(ex.errors).to eq ['Missing required configuration key: blog/db/name']
57
55
  }
58
56
  end
59
57
 
60
58
  it 'returns an empty collection if there are no errors' do
61
- Prodder::Config.new(valid_config).lint!.should == []
59
+ expect(Prodder::Config.new(valid_config).lint!).to eq []
62
60
  end
63
61
  end
64
62
  end
@@ -1,3 +1,7 @@
1
1
  require 'rspec'
2
2
  require 'pry'
3
3
  require 'prodder'
4
+
5
+ RSpec.configure do |config|
6
+ config.disable_monkey_patching!
7
+ 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.7
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: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deject
@@ -35,7 +35,6 @@ files:
35
35
  - ".gitignore"
36
36
  - ".travis.yml"
37
37
  - Gemfile
38
- - Gemfile.lock
39
38
  - LICENSE.txt
40
39
  - README.md
41
40
  - Rakefile
@@ -82,8 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
81
  - !ruby/object:Gem::Version
83
82
  version: '0'
84
83
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.6.8
84
+ rubygems_version: 3.0.8
87
85
  signing_key:
88
86
  specification_version: 4
89
87
  summary: Maintain your Rails apps' structure, seed and quality_checks files using
@@ -1,64 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- aruba (0.5.1)
5
- childprocess (~> 0.3.6)
6
- cucumber (>= 1.1.1)
7
- rspec-expectations (>= 2.7.0)
8
- benzo (2.0.0)
9
- cocaine (~> 0.4.2)
10
- builder (3.1.4)
11
- childprocess (0.3.6)
12
- ffi (~> 1.0, >= 1.0.6)
13
- cocaine (0.4.2)
14
- coderay (1.0.8)
15
- cucumber (1.2.1)
16
- builder (>= 2.1.2)
17
- diff-lcs (>= 1.1.3)
18
- gherkin (~> 2.11.0)
19
- json (>= 1.4.6)
20
- deject (0.2.3)
21
- diff-lcs (1.1.3)
22
- ffi (1.2.0)
23
- gherkin (2.11.5)
24
- json (>= 1.4.6)
25
- json (1.8.3)
26
- method_source (0.8.1)
27
- pg (0.18.2)
28
- pry (0.9.10)
29
- coderay (~> 1.0.5)
30
- method_source (~> 0.8)
31
- slop (~> 3.3.1)
32
- pry-remote (0.1.6)
33
- pry (~> 0.9)
34
- slop (~> 3.0)
35
- rake (10.0.3)
36
- rspec (2.12.0)
37
- rspec-core (~> 2.12.0)
38
- rspec-expectations (~> 2.12.0)
39
- rspec-mocks (~> 2.12.0)
40
- rspec-core (2.12.2)
41
- rspec-expectations (2.12.1)
42
- diff-lcs (~> 1.1.3)
43
- rspec-mocks (2.12.1)
44
- slop (3.3.3)
45
- thor (0.16.0)
46
-
47
- PLATFORMS
48
- ruby
49
-
50
- DEPENDENCIES
51
- aruba
52
- benzo
53
- cocaine
54
- cucumber
55
- deject
56
- pg
57
- pry
58
- pry-remote
59
- rake
60
- rspec
61
- thor
62
-
63
- BUNDLED WITH
64
- 1.11.2