Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix usage of psql in db:test:prepare #4834

Merged
merged 1 commit into from

3 participants

@sskirby

Re-submit of #4810

According to http://www.postgresql.org/docs/9.1/static/app-psql.html (which hasn't changed since at least version 7.0), the psql command line tool optionally takes a username as its last argument. However, the rake db:test:prepare task is mistakenly passing in the template database from database.yml.

This bug probably hasn't been discovered until now because it requires users to be using a sql schema dump (by using in application.rb: config.active_record.schema_format = :sql) AND to have specified a template in their database.yml.

@chris-baynes

Also spotted this, but the user argument is still missing.
set_psql_env should be handling this, but the rake tasks fail unless I provide an explicit user argument:

`psql -U #{abcs[env]['username']} -f "#{filename}" #{abcs[env]['database']}`
@sskirby

That's very strange, Chris, because my change only removes passing in the template as the last argument. If what you are saying is correct, db:test:prepare should not be working at all in master. Which means no one using PostgreSQL is able to run tests via the standard rake task.

Now that I think of it, however, I did only test the change as it applies to the 3-2-stable branch and not master. I will re-test against master. If something is wrong, I suspect that it's not because of the changes in this patch.

@chris-baynes

Well, by default psql uses the current OS user name if one isn't provided on the command line. Are you also running the rake tasks as a user that does not have direct access to the db? If so I'll have to check what's wrong with my environment.

@sskirby

Just tested my patch against the latest master branch and (after applying #4910) everything seems to work just fine. I do not have a pg user that matches my username.

@sskirby

Just wondering if the suspicion that a username needs to be explicitly passed in to psql is what's keeping this pull request from being accepted.

If that's the case, the username issue is really a completely different issue and has nothing to do with the changes in this pull request. It should not be blocking this pull request, it should be in it's own ticket.

@chris-baynes

@sskirby agreed. I've tested your patch in another environment and everything's working fine.
+1 for the pull request

@tenderlove tenderlove merged commit 957da55 into rails:master
@tenderlove tenderlove referenced this pull request from a commit
@tenderlove tenderlove Merge branch '3-2-2' into 3-2-stable
* 3-2-2:
  bumping to 3.2.2
  Ensure [] respects the status of the buffer.
  Merge pull request #4834 from sskirby/fix_usage_of_psql_in_db_test_prepare
  Merge pull request #5084 from johndouthat/patch-1
  updating RAILS_VERSION
  delete vulnerable AS::SafeBuffer#[]
  use AS::SafeBuffer#clone_empty for flushing the output_buffer
  add AS::SafeBuffer#clone_empty
  fix output safety issue with select options
c289790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 1, 2012
  1. @sskirby

    fixes rake db:test:prepare when using postgresql with sql db structur…

    sskirby authored
    …e file and specifying a template in database.yml
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  activerecord/lib/active_record/railties/databases.rake
View
2  activerecord/lib/active_record/railties/databases.rake
@@ -420,7 +420,7 @@ db_namespace = namespace :db do
end
when /postgresql/
set_psql_env(abcs[env])
- `psql -f "#{filename}" #{abcs[env]['database']} #{abcs[env]['template']}`
+ `psql -f "#{filename}" #{abcs[env]['database']}`
when /sqlite/
dbfile = abcs[env]['database']
`sqlite3 #{dbfile} < "#{filename}"`
Something went wrong with that request. Please try again.