prodder 1.8.2 → 1.9.0

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/Gemfile +4 -2
  4. data/Gemfile.lock +122 -0
  5. data/LICENSE.txt +5 -7
  6. data/README.md +173 -81
  7. data/compose.yml +2 -2
  8. data/cucumber.yml +1 -0
  9. data/features/step_definitions/git_steps.rb +18 -18
  10. data/features/step_definitions/prodder_steps.rb +26 -26
  11. data/features/support/blog.git/HEAD +1 -0
  12. data/features/support/blog.git/config +7 -0
  13. data/features/support/blog.git/description +1 -0
  14. data/features/support/blog.git/hooks/applypatch-msg.sample +15 -0
  15. data/features/support/blog.git/hooks/commit-msg.sample +24 -0
  16. data/features/support/blog.git/hooks/post-commit.sample +8 -0
  17. data/features/support/blog.git/hooks/post-receive.sample +15 -0
  18. data/features/support/blog.git/hooks/post-update.sample +8 -0
  19. data/features/support/blog.git/hooks/pre-applypatch.sample +14 -0
  20. data/features/support/blog.git/hooks/pre-commit.sample +46 -0
  21. data/features/support/blog.git/hooks/pre-rebase.sample +169 -0
  22. data/features/support/blog.git/hooks/prepare-commit-msg.sample +36 -0
  23. data/features/support/blog.git/hooks/update.sample +128 -0
  24. data/features/support/blog.git/info/exclude +6 -0
  25. data/features/support/blog.git/objects/2c/0dfde112cb834fc1bd166454bf0e23f35aec0b +0 -0
  26. data/features/support/blog.git/objects/5f/344dad802e30fce4f8b84e094a52a0a3c1ef9a +0 -0
  27. data/features/support/blog.git/objects/c0/7cd3c46c7a18b6b2c44f4efea77554d0840056 +0 -0
  28. data/features/support/blog.git/packed-refs +2 -0
  29. data/features/support/env.rb +22 -10
  30. data/lib/prodder/cli.rb +0 -2
  31. data/lib/prodder/pg.rb +8 -6
  32. data/lib/prodder/prodder.rake +9 -9
  33. data/lib/prodder/version.rb +1 -1
  34. data/prodder.gemspec +6 -4
  35. data/rspec_test.log +5 -0
  36. metadata +45 -10
  37. data/.dockerignore +0 -2
  38. data/.github/workflows/ci.yml +0 -69
  39. data/.gitignore +0 -2
  40. data/entrypoints/entry.sh +0 -15
@@ -1,9 +1,16 @@
1
1
  require 'cucumber'
2
2
  require 'aruba/cucumber'
3
3
 
4
- $LOAD_PATH.unshift File.expand_path('../../lib', File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __dir__)
5
5
  require 'prodder'
6
6
 
7
+ # Configure Aruba to find the prodder executable
8
+ Aruba.configure do |config|
9
+ config.command_search_paths << File.expand_path('../../bin', __dir__)
10
+ config.exit_timeout = 10
11
+ config.io_wait_timeout = 10
12
+ end
13
+
7
14
  module ProdderHelpers
8
15
  def strip_leading(string)
9
16
  leading = string.scan(/^\s*/).min_by &:length
@@ -11,21 +18,21 @@ module ProdderHelpers
11
18
  end
12
19
 
13
20
  def in_workspace(name, &block)
14
- in_current_dir { Dir.chdir("prodder-workspace/#{name}", &block) }
21
+ in_current_directory { Dir.chdir("prodder-workspace/#{name}", &block) }
15
22
  end
16
23
 
17
24
  def commit_to_remote(project)
18
25
  @dirs = ['tmp', 'aruba']
19
- run_simple "git clone repos/#{project}.git tmp-extra-commit-#{project}"
26
+ run_command_and_stop "git clone repos/#{project}.git tmp-extra-commit-#{project}"
20
27
  cd "tmp-extra-commit-#{project}"
21
28
 
22
29
  append_to_file "README", 'Also read this!'
23
- run_simple 'git add README'
24
- run_simple 'git commit -m "Second commit"'
25
- run_simple "git push origin master"
30
+ run_command_and_stop 'git add README'
31
+ run_command_and_stop 'git -c user.email="test@example.com" -c user.name="Test User" commit -m "Second commit"'
32
+ run_command_and_stop "git push origin master"
26
33
 
27
34
  cd '..'
28
- run_simple "rm -rf tmp-extra-commit-#{project}"
35
+ run_command_and_stop "rm -rf tmp-extra-commit-#{project}"
29
36
  end
30
37
 
31
38
  def update_config(filename, &block)
@@ -90,7 +97,7 @@ module ProdderHelpers
90
97
  end
91
98
 
92
99
  def self.fixture_dbs
93
- @fixture_dbs ||= Dir[File.join(File.dirname(__FILE__), '*.sql')].map do |sql|
100
+ @fixture_dbs ||= Dir[File.join(__dir__, '*.sql')].map do |sql|
94
101
  db = File.basename(sql).sub('.sql', '')
95
102
  [db, File.read(sql)]
96
103
  end
@@ -100,10 +107,15 @@ end
100
107
  World ProdderHelpers
101
108
 
102
109
  Before do
103
- @prodder_root = File.expand_path('../..', File.dirname(__FILE__))
110
+ @prodder_root = File.expand_path('../..', __dir__)
104
111
  @aruba_root = File.join(@prodder_root, 'tmp', 'aruba')
105
- @aruba_timeout_seconds = 10
106
112
  Dir.chdir @prodder_root
113
+
114
+ # Configure git for tests that create commits
115
+ set_environment_variable 'GIT_AUTHOR_NAME', 'Test User'
116
+ set_environment_variable 'GIT_AUTHOR_EMAIL', 'test@example.com'
117
+ set_environment_variable 'GIT_COMMITTER_NAME', 'Test User'
118
+ set_environment_variable 'GIT_COMMITTER_EMAIL', 'test@example.com'
107
119
  end
108
120
 
109
121
  After('@restore-perms') do
data/lib/prodder/cli.rb CHANGED
@@ -2,8 +2,6 @@ require 'prodder'
2
2
  require 'thor'
3
3
  require 'yaml'
4
4
 
5
- require 'pp' # TODO rm
6
-
7
5
  class Prodder::CLI < Thor
8
6
  include Thor::Actions
9
7
 
data/lib/prodder/pg.rb CHANGED
@@ -70,11 +70,12 @@ module Prodder
70
70
  end
71
71
  end
72
72
 
73
- def dump_structure(db_name, filename, options = {})
73
+ def dump_structure(db_name, filename, **options)
74
74
  arguments = [
75
75
  '--schema-only',
76
76
  '--no-privileges',
77
77
  '--no-owner',
78
+ '--restrict-key', 'prodder',
78
79
  '--host', credentials['host'],
79
80
  '--username', credentials['user']
80
81
  ]
@@ -96,6 +97,7 @@ module Prodder
96
97
  '--no-privileges',
97
98
  '--no-owner',
98
99
  '--disable-triggers',
100
+ '--restrict-key', 'prodder',
99
101
  '--host', credentials['host'],
100
102
  '--username', credentials['user'],
101
103
  *tables.map { |table| ['--table', table] }.flatten,
@@ -103,12 +105,12 @@ module Prodder
103
105
  ]
104
106
  end
105
107
 
106
- def dump_permissions(db_name, filename, options = {})
108
+ def dump_permissions(db_name, filename, **options)
107
109
  perm_out_sql = ""
108
110
  user_list = []
109
111
 
110
- perm_out_sql << dump_db_access_control(db_name, user_list, options)
111
- perm_out_sql.prepend pg_dumpall db_name, user_list, options
112
+ perm_out_sql << dump_db_access_control(db_name, user_list, **options)
113
+ perm_out_sql.prepend pg_dumpall(db_name, user_list, **options)
112
114
 
113
115
  perm_out_sql.prepend(alter_role_function)
114
116
  perm_out_sql.prepend(create_role_function)
@@ -127,7 +129,7 @@ module Prodder
127
129
  DEFAULT_PRIVILEGES = /^ALTER DEFAULT PRIVILEGES /
128
130
  SET_OBJECT_OWNERSHIP = /.* OWNER TO /
129
131
 
130
- def dump_db_access_control(db_name, user_list, options)
132
+ def dump_db_access_control(db_name, user_list, **options)
131
133
  perm_out_sql = ""
132
134
  arguments = [
133
135
  '--schema-only',
@@ -218,7 +220,7 @@ module Prodder
218
220
  end
219
221
  end
220
222
 
221
- def pg_dumpall(db_name, user_list, options)
223
+ def pg_dumpall(db_name, user_list, **options)
222
224
  white_list = options[:included_users] || []
223
225
  irrelevant_login_roles = irrelevant_login_roles(db_name, white_list).map { |user| user['oid'] }
224
226
 
@@ -169,7 +169,7 @@ namespace :db do
169
169
  end
170
170
  as("superuser", in: environments) do
171
171
  ActiveRecord::Tasks::DatabaseTasks.create_current
172
- ActiveRecord::Base.configurations.to_h.each do |env, config|
172
+ Rails.configuration.database_configuration.each do |env, config|
173
173
  if environments.include?(env) && config["migration_user"] && config['database']
174
174
  set_psql_env config
175
175
  `psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}`
@@ -182,7 +182,7 @@ namespace :db do
182
182
  task :all => dependencies do
183
183
  as("superuser") do
184
184
  ActiveRecord::Tasks::DatabaseTasks.create_all
185
- ActiveRecord::Base.configurations.to_h.each do |env, config|
185
+ Rails.configuration.database_configuration.each do |env, config|
186
186
  if config["migration_user"] && config['database']
187
187
  set_psql_env config
188
188
  `psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}`
@@ -362,19 +362,19 @@ namespace :db do
362
362
 
363
363
  def as(user, opts = {}, &block)
364
364
  if File.exist?('db/permissions.sql')
365
- original_config = ActiveRecord::Base.configurations.deep_dup
366
- in_env = Array(opts[:in]) || ActiveRecord::Base.configurations.deep_dup.to_h.keys
367
- disconnect
368
- in_env.each do |env|
369
- config = ActiveRecord::Base.configurations.find_db_config(env)
370
- config["username"] = config[user]
365
+ config, config_was = Rails.configuration.database_configuration, ActiveRecord::Base.configurations.deep_dup
366
+ in_env = Array(opts[:in]) || config.keys
367
+ if config.all? { |env, config_hash| in_env.include?(env) ? config_hash[user] : true }
368
+ disconnect
369
+ config.each { |env, config_hash| config_hash["username"] = config_hash[user] if in_env.include?(env) }
370
+ ActiveRecord::Base.configurations = config
371
371
  end
372
372
  else
373
373
  puts "No permissions file (db/permissions.sql) found, running everything in context of user"
374
374
  end
375
375
  yield
376
376
  ensure
377
- ActiveRecord::Base.configurations = original_config if original_config
377
+ ActiveRecord::Base.configurations = config_was if config_was
378
378
  in_env.each { |env| ActiveRecord::Base.establish_connection(env.intern) } if in_env
379
379
  end
380
380
 
@@ -1,3 +1,3 @@
1
1
  module Prodder
2
- VERSION = "1.8.2"
2
+ VERSION = "1.9.0"
3
3
  end
data/prodder.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(File.expand_path("lib", __dir__))
3
3
  require "prodder/version"
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -12,11 +12,13 @@ Gem::Specification.new do |s|
12
12
  s.summary = "Maintain your Rails apps' structure, seed and quality_checks files using production dumps"
13
13
  s.description = "Migrations suck long-term. Now you can kill them routinely."
14
14
 
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.files = Dir.glob("{lib,bin,features}/**/*") + Dir.glob("*").reject { |f| File.directory?(f) }
16
+ s.test_files = Dir.glob("{test,spec,features}/**/*")
17
+ s.executables = Dir.glob("bin/*").map { |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
+ s.required_ruby_version = ">= 2.7.0"
21
+
20
22
  # These dependencies do not match the Gemfile's for a reason.
21
23
  # These are the only dependencies necessary to satisfy inclusion of this
22
24
  # gem in a Rails application; any dependencies necessary to run prodder
data/rspec_test.log ADDED
@@ -0,0 +1,5 @@
1
+ .............
2
+
3
+ Finished in 0.01093 seconds (files took 0.16398 seconds to load)
4
+ 13 examples, 0 failures
5
+
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.8.2
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Hargraves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-03 00:00:00.000000000 Z
11
+ date: 2025-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deject
@@ -32,17 +32,15 @@ executables:
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".dockerignore"
36
- - ".github/workflows/ci.yml"
37
- - ".gitignore"
38
35
  - Dockerfile
39
36
  - Gemfile
37
+ - Gemfile.lock
40
38
  - LICENSE.txt
41
39
  - README.md
42
40
  - Rakefile
43
41
  - bin/prodder
44
42
  - compose.yml
45
- - entrypoints/entry.sh
43
+ - cucumber.yml
46
44
  - features/commit.feature
47
45
  - features/dump.feature
48
46
  - features/init.feature
@@ -52,6 +50,24 @@ files:
52
50
  - features/step_definitions/git_steps.rb
53
51
  - features/step_definitions/prodder_steps.rb
54
52
  - features/support/blog.git.tgz
53
+ - features/support/blog.git/HEAD
54
+ - features/support/blog.git/config
55
+ - features/support/blog.git/description
56
+ - features/support/blog.git/hooks/applypatch-msg.sample
57
+ - features/support/blog.git/hooks/commit-msg.sample
58
+ - features/support/blog.git/hooks/post-commit.sample
59
+ - features/support/blog.git/hooks/post-receive.sample
60
+ - features/support/blog.git/hooks/post-update.sample
61
+ - features/support/blog.git/hooks/pre-applypatch.sample
62
+ - features/support/blog.git/hooks/pre-commit.sample
63
+ - features/support/blog.git/hooks/pre-rebase.sample
64
+ - features/support/blog.git/hooks/prepare-commit-msg.sample
65
+ - features/support/blog.git/hooks/update.sample
66
+ - features/support/blog.git/info/exclude
67
+ - features/support/blog.git/objects/2c/0dfde112cb834fc1bd166454bf0e23f35aec0b
68
+ - features/support/blog.git/objects/5f/344dad802e30fce4f8b84e094a52a0a3c1ef9a
69
+ - features/support/blog.git/objects/c0/7cd3c46c7a18b6b2c44f4efea77554d0840056
70
+ - features/support/blog.git/packed-refs
55
71
  - features/support/env.rb
56
72
  - features/support/prodder__blog_prod.sql
57
73
  - lib/prodder.rb
@@ -64,6 +80,7 @@ files:
64
80
  - lib/prodder/railtie.rb
65
81
  - lib/prodder/version.rb
66
82
  - prodder.gemspec
83
+ - rspec_test.log
67
84
  - spec/config_spec.rb
68
85
  - spec/spec_helper.rb
69
86
  homepage: https://github.com/enova/prodder
@@ -78,19 +95,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
95
  requirements:
79
96
  - - ">="
80
97
  - !ruby/object:Gem::Version
81
- version: '0'
98
+ version: 2.7.0
82
99
  required_rubygems_version: !ruby/object:Gem::Requirement
83
100
  requirements:
84
101
  - - ">="
85
102
  - !ruby/object:Gem::Version
86
103
  version: '0'
87
104
  requirements: []
88
- rubygems_version: 3.3.26
105
+ rubygems_version: 3.5.22
89
106
  signing_key:
90
107
  specification_version: 4
91
108
  summary: Maintain your Rails apps' structure, seed and quality_checks files using
92
109
  production dumps
93
110
  test_files:
111
+ - spec/config_spec.rb
112
+ - spec/spec_helper.rb
94
113
  - features/commit.feature
95
114
  - features/dump.feature
96
115
  - features/init.feature
@@ -99,8 +118,24 @@ test_files:
99
118
  - features/push.feature
100
119
  - features/step_definitions/git_steps.rb
101
120
  - features/step_definitions/prodder_steps.rb
121
+ - features/support/blog.git/HEAD
122
+ - features/support/blog.git/config
123
+ - features/support/blog.git/description
124
+ - features/support/blog.git/hooks/applypatch-msg.sample
125
+ - features/support/blog.git/hooks/commit-msg.sample
126
+ - features/support/blog.git/hooks/post-commit.sample
127
+ - features/support/blog.git/hooks/post-receive.sample
128
+ - features/support/blog.git/hooks/post-update.sample
129
+ - features/support/blog.git/hooks/pre-applypatch.sample
130
+ - features/support/blog.git/hooks/pre-commit.sample
131
+ - features/support/blog.git/hooks/pre-rebase.sample
132
+ - features/support/blog.git/hooks/prepare-commit-msg.sample
133
+ - features/support/blog.git/hooks/update.sample
134
+ - features/support/blog.git/info/exclude
135
+ - features/support/blog.git/objects/2c/0dfde112cb834fc1bd166454bf0e23f35aec0b
136
+ - features/support/blog.git/objects/5f/344dad802e30fce4f8b84e094a52a0a3c1ef9a
137
+ - features/support/blog.git/objects/c0/7cd3c46c7a18b6b2c44f4efea77554d0840056
138
+ - features/support/blog.git/packed-refs
102
139
  - features/support/blog.git.tgz
103
140
  - features/support/env.rb
104
141
  - features/support/prodder__blog_prod.sql
105
- - spec/config_spec.rb
106
- - spec/spec_helper.rb
data/.dockerignore DELETED
@@ -1,2 +0,0 @@
1
- Gemfile.lock
2
- tmp
@@ -1,69 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- workflow_dispatch:
5
- push:
6
- branches:
7
- - main
8
- pull_request_target:
9
- branches:
10
- - main
11
-
12
- permissions:
13
- contents: read
14
-
15
- jobs:
16
- test:
17
- runs-on: ubuntu-latest
18
- strategy:
19
- fail-fast: false
20
- matrix:
21
- ruby-version: [2.6, 2.7, 3.0]
22
- services:
23
- postgres:
24
- image: postgres:13-alpine
25
- ports:
26
- - 5432:5432
27
- env:
28
- POSTGRES_USER: postgres
29
- POSTGRES_PASSWORD: postgres
30
- POSTGRES_HOST_AUTH_METHOD: trust
31
- options: >-
32
- --health-cmd pg_isready
33
- --health-interval 10s
34
- --health-timeout 5s
35
- --health-retries 5
36
- steps:
37
- - name: Checkout Project
38
- uses: actions/checkout@v4
39
- - name: Set up Ruby
40
- uses: ruby/setup-ruby@v1
41
- with:
42
- ruby-version: ${{ matrix.ruby-version }}
43
- bundler-cache: true
44
- - name: Install Library Dependencies
45
- run: sudo apt update && sudo apt install -y postgresql-client
46
- - name: Setup Database
47
- run: |
48
- mkdir -p config
49
- cat <<EOF > config/database.yml
50
- test:
51
- adapter: postgresql
52
- encoding: unicode
53
- pool: 20
54
- database: prodder_test
55
- EOF
56
- - name: Test with RSpec
57
- env:
58
- PGHOST: localhost
59
- PGPORT: 5432
60
- PGUSER: postgres
61
- PGPASSWORD: postgres
62
- run: bundle exec rspec
63
- - name: Test with Cucumber
64
- env:
65
- PGHOST: localhost
66
- PGPORT: 5432
67
- PGUSER: postgres
68
- PGPASSWORD: postgres
69
- run: bundle exec cucumber
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- Gemfile.lock
2
- tmp
data/entrypoints/entry.sh DELETED
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
-
4
- cmd=("$@")
5
-
6
- mkdir -p config
7
- cat <<EOF > config/database.yml
8
- test:
9
- adapter: postgresql
10
- encoding: unicode
11
- pool: 20
12
- database: prodder_test
13
- EOF
14
-
15
- exec "${cmd[@]}"