Jack Baty
2005-Nov-07 20:59 UTC
Running ''rake'' empties production database if RAILS_ENV = ''production''
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
Jeremy Kemper
2005-Nov-07 21:33 UTC
Re: Running ''rake'' empties production database if RAILS_ENV = ''production''
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Nov 7, 2005, at 12:59 PM, Jack Baty wrote:> 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)...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-----
Jack Baty
2005-Nov-07 21:48 UTC
Re: Running ''rake'' empties production database if RAILS_ENV = ''production''
On 11/7/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> 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
Jeremy Kemper
2005-Nov-07 21:57 UTC
Re: Running ''rake'' empties production database if RAILS_ENV = ''production''
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Nov 7, 2005, at 1:48 PM, Jack Baty wrote:> On 11/7/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> 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.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-----
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]-- Posted via http://www.ruby-forum.com/.