prodder 1.7.2 → 1.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +6 -17
- data/Gemfile +2 -2
- data/README.md +3 -3
- data/features/commit.feature +3 -3
- data/features/dump.feature +7 -7
- data/features/prodder.feature +1 -1
- data/features/push.feature +1 -1
- data/features/step_definitions/git_steps.rb +10 -8
- data/features/support/prodder__blog_prod.sql +1 -0
- data/lib/prodder/pg.rb +16 -23
- data/lib/prodder/prodder.rake +56 -48
- data/lib/prodder/project.rb +1 -2
- data/lib/prodder/version.rb +1 -1
- data/spec/config_spec.rb +5 -7
- data/spec/spec_helper.rb +4 -0
- metadata +3 -5
- data/Gemfile.lock +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 837adeb9529887b429bbe128bbb9162f29d0ca5001fbd94b28aba2aa105caacb
|
4
|
+
data.tar.gz: e3b410b12794de3b1a04d55adad8ac789c83658526c4a749b8494878381c7e0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5982600241c08dc3c623c8c1e6153cfbd10bd6c20f3fa3074f4cf45335f6fd091c58e31e2e26da624c956b6624458ce21ce117568b933ec72aab8f2f30d295d
|
7
|
+
data.tar.gz: 697799d716ab1bd9a7fbc19b3a346681621ffd8cf3b732ee2eed41acb86b7626fb0eb16f239a307c62c797f890a1cfc9c8e2d6db367fb1542ed174ca14512aee
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -2,24 +2,20 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.2
|
7
|
-
- 2.1.8
|
5
|
+
- 2.5.8
|
6
|
+
- 2.7.2
|
8
7
|
|
9
8
|
env:
|
10
9
|
matrix:
|
11
|
-
- PG_VERSION=
|
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
|
19
|
-
-
|
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
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
|
6
|
-
table contents, based on its migration history
|
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
|
|
data/features/commit.feature
CHANGED
@@ -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"
|
data/features/dump.feature
CHANGED
@@ -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"
|
data/features/prodder.feature
CHANGED
data/features/push.feature
CHANGED
@@ -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 "
|
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
|
-
|
9
|
-
|
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.
|
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.
|
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.
|
48
|
+
expect(changed).to_not be_empty
|
47
49
|
|
48
50
|
diff = `git show HEAD | grep '#{content}'`.split("\n")
|
49
|
-
diff.
|
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.
|
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.
|
65
|
+
expect(latest).to_not be_empty
|
64
66
|
end
|
65
67
|
end
|
data/lib/prodder/pg.rb
CHANGED
@@ -42,8 +42,8 @@ module Prodder
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def dump_settings(db_name, filename)
|
45
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
data/lib/prodder/prodder.rake
CHANGED
@@ -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
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
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
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
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
|
-
|
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
|
data/lib/prodder/project.rb
CHANGED
@@ -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(
|
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
|
|
data/lib/prodder/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -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}").
|
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').
|
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.
|
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
|
59
|
+
expect(Prodder::Config.new(valid_config).lint!).to eq []
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
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:
|
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
|
-
|
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
|
data/Gemfile.lock
DELETED
@@ -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
|