[LRUG] database account used by migrations

Jonathan Leighton j at jonathanleighton.com
Fri Dec 14 05:31:13 PST 2007


Incidentally, I was delighted this week to discover that Postgres can do
transactional DDL, and this plugin rolls that into Rails:
http://www.redhillonrails.org/#transactional_migrations

I swear it's already saved me about half an hour or so of repairing
half-migrated databases :)

Jon

On Fri, 2007-12-14 at 13:26 +0000, James Adam wrote:
> On 12/14/07, Scott Rutherford <scott at cominded.com> wrote:
> > Hi Dafydd,
> >
> > Alter config/database.yml
> >
> 
> I Think Dafydd's question was more related to security - it seems he
> doesn't want the account that ActiveRecord normally uses to have ANY
> permission to alter the schema. Or something like that.
> 
> You can achieve this by working with database.yml:
> 
>   development_defaults: &development_defaults
>     adapter: mysql
>     database: my_app_dev
>     host: localhost
> 
>   development:
>     <<: *development_defaults
>     username: user_with_read_access
>     password: password_for_that_user
> 
>   development_migration
>     <<: *development_defaults
>     username: super_user_with_alter_access
>     password: password_for_that_super_user
> 
> 
> .... and so on for the other environments that you care about. Then,
> when you want to migrate, you just need to set the environment like
> so:
> 
>   $ RAILS_ENV=development_migration rake db:migrate
> 
> And it should connect with the creditials you've given.
> 
> This isn't fool-proof, however - if you rely on the environment
> variable to load any other configuration (i.e. via
> config/environments/development.rb), you'll need to deal with that
> somehow too.
> 
> -~*~-
> 
> Here's another (probably better) approach using environment variables
> and the fact that database.yml is parsed through ERB:
> 
>   development:
>     adapter: mysql
>     database: my_app_dev
>     host: localhost
>     username: <%= ENV['RAILS_USER'] || 'default_username' %>
>     password: <%= ENV['RAILS_PASSWORD'] || 'default_password' %>
> 
> That way if you run
> 
>   $ RAILS_USER=super_user RAILS_PASSWORD=their_password rake db:migrate
> 
> ...it will pick up the creditials you've given on the command line.
> 
> HTH,
> 
> James
> 
-- 
Jonathan Leighton, Web Developer
http://jonathanleighton.com/




More information about the Chat mailing list