Running 'rake' empties production database if RAILS_ENV = 'p


#1

I just ran rake on a development site on a server, which I typically
don’t do, while trying to test what I thought to be a server-related
issue. When rake finished (all tests passed) the production database
was wiped, leaving only fixture data. I subsequently noticed that in
the dev site’s ‘environment.rb’ I had uncommented the line…

ENV[‘RAILS_ENV’] = ‘production’

The site_test database was unchanged. I believe the database.yml file
is configured correctly (test environment points to my _test
database)…

test:
adapter: mysql
database: site_test
host: localhost
username: jbaty
password: mypassword

production:
adapter: mysql
database: site_production
host: localhost
username: jbaty
password: mypassword

It’s a tad disconcerting that typing “rake” in the wrong directory
could have that sort of effect. Shouldn’t rake always target the
test environment database, regardless of environment rails is running?
Or perhaps I just don’t understand something.


Jack Baty
Fusionary Media - http://www.fusionary.com


#2

On Nov 7, 2005, at 12:59 PM, Jack Baty wrote:

database)…
Argh! Sorry to hear that.

It’s a tad disconcerting that typing “rake” in the wrong directory
could have that sort of effect. Shouldn’t rake always target the
test environment database, regardless of environment rails is running?
Or perhaps I just don’t understand something.

Indeed. It does in the 1.0 release candidates to prevent this scenario.

RAILS_ENV is specifiable as an environment variable so you don’t have to
hardcode it in environment.rb – you may set it from outside your
Rails app,
such as in your FastCGI configuration.

See the -init-env option for Apache mod_fastcgi and the bin-environment
option for lighttpd. For example (lighttpd):

fastcgi.server = (
“.fcgi” => (
“myapp” => (
“min-procs” => 2,
“max-procs” => 2,
“socket” => “/tmp/myapp_fcgi_1.sock”,
“bin-path” => “public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)
)
)

jeremy


#3

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 7, 2005, at 1:48 PM, Jack Baty wrote:

such as in your FastCGI configuration.

See the -init-env option for Apache mod_fastcgi and the bin-
environment
option for lighttpd. For example (lighttpd): [snip]

That’s how I do it with lighttpd, but mod_fastcgi has always been
difficult for me to get right, so I’ve been known to cheat and simply
change it in environment.rb. I’m trying to wean myself of that though.

Apache FastCGI configuration is notoriously aggravating.

We’re adding some further safeguards right now to keep this from ever
happening.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDb83NAQHALep9HFYRAgOKAJ4oGbfKqUzvAbbCxIsdxY5M1w1GcgCdGRmN
KntzLBRafVld6R/JsNcUjOA=
=KkmS
-----END PGP SIGNATURE-----


#4

On 11/7/05, Jeremy K. removed_email_address@domain.invalid wrote:

Argh! Sorry to hear that.

Thanks. Fortunately, frequent backups have made this into only a minor
inconvenience.

RAILS_ENV is specifiable as an environment variable so you don’t have to
hardcode it in environment.rb – you may set it from outside your
Rails app,
such as in your FastCGI configuration.

See the -init-env option for Apache mod_fastcgi and the bin-environment
option for lighttpd. For example (lighttpd): [snip]

That’s how I do it with lighttpd, but mod_fastcgi has always been
difficult for me to get right, so I’ve been known to cheat and simply
change it in environment.rb. I’m trying to wean myself of that though.


Jack Baty
Fusionary Media - http://www.fusionary.com


#5

Any suggestions if you’re running in a shared environment and don’t have
access to the apache/lighttpd config? This problem is killing me.

Ha this been submitted as a bug?

Thanks.

–Ryan

jeremy wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 7, 2005, at 1:48 PM, Jack Baty wrote:

such as in your FastCGI configuration.

See the -init-env option for Apache mod_fastcgi and the bin-
environment
option for lighttpd. For example (lighttpd): [snip]