On 13 August 2010 00:08, Fearless Fool <lists@ruby-forum.com> wrote:
> Short form: How can I convince migrate to create or modify tables in a
> database other than the "current" one? In other words, how can I get
> migrate to honor establish_connection :external in a model definition?
>
> Details: I have a large "almost static" dataset that never changes as a
> result of my Rails app, so it's residing in a separate database. (It
> gets refreshed nightly with external data.) I'd like to maintain its
> schema using the Rails migration mechanism, but despite my efforts,
> migrate only updates tables for the current environment (e.g.
> _development or _test).
>
> Here's a stripped down example:
>
> === MODELS (in app/models):
> class Hat < ActiveRecord::Base
> establish_connection :external # use external database
> end
>
> === SCHEMA (in db/schema.rb, lightly edited):
> ActiveRecord::Schema.define(:version => 20100812225348) do
> create_table "hats", :force => true do |t|
> t.string "style"
> end
> end
>
> === TABLE DEFINITIONS (in config/database.yml, only showing first two
> entries):
> development:
> adapter: mysql
> encoding: utf8
> reconnect: false
> database: dbtest_development
> pool: 5
> username: root
> password: XYZZY
> socket: /tmp/mysql.sock
>
> external:
> adapter: mysql
> encoding: utf8
> reconnect: false
> database: dbtest_external
> pool: 5
> username: root
> password: XYZZY
> socket: /tmp/mysql.sock
>
> === SYNOPSIS:
> $ rails new dbtest
> $ cd dbtest
> $ <edit config/database.yml to add external table spec>
> $ rake db:create:all
> $ rails generate model Hat style:string
> $ <edit models/hat.rb to include establish_connection as shown above>
> $ rake db:migrate
Am I misunderstanding your question, or is it just a matter of doing
rake db_migrate RAILS_ENV=external
to migrate that db?
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment