Forum: Ruby on Rails Running 'rake' empties production database if RAILS_ENV = 'p

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
251e19913d21aa40a99ec00ed18d202d?d=identicon&s=25 jbaty (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 jeremy (Guest)
on 2005-11-12 12:49
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDb8gfAQHALep9HFYRAnPFAKC7FPIwcQOTCRu0RMydXDk6EcX9dgCdHZ9z
yL6foIsHVlTOu+1YVjgqfJs=
=ANTZ
-----END PGP SIGNATURE-----
251e19913d21aa40a99ec00ed18d202d?d=identicon&s=25 jbaty (Guest)
on 2005-11-12 12:49
(Received via mailing list)
On 11/7/05, Jeremy Kemper <jeremy@bitsweat.net> 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
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 jeremy (Guest)
on 2005-11-12 12:49
(Received via mailing list)
-----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-----
E37ca8b3eee534fa6781f7ba13743afb?d=identicon&s=25 Ryan (Guest)
on 2005-12-27 18:58
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]
This topic is locked and can not be replied to.