I agree, test environment should not evolve the schema, instead depend on
an existing schema. So I think it makes sense not to generate schema if at
all I choose to run migrations in the test environment.


On 4 February 2014 17:16, Xavier Noria <f...@hashref.com> wrote:

> On Tue, Feb 4, 2014 at 12:17 PM, tkrd <t-kur...@oiax.jp> wrote:
>
> Xavier, you wrote that we are not supposed to run migrations with
>> RAILS_ENV=test, but the Rails itself occasionally prompts us to do it.
>>
>> For example, when I run rspec command having pending migrations on test
>> environment, the Rails emits the following message:
>>
>> > Migrations are pending. To resolve this issue, run:
>> >
>> > bin/rake db:migrate RAILS_ENV=test
>>
>> This message is embedded in /activerecord/lib/active_record/migration.rb.
>>
>> I am not sure if this message is a correct instruction or not, though.
>>
>
> I believe that message is not consistent with the golden path.
>
> The big guidelines here are:
>
> * Migrations run to evolve the schema. As a side-effect, running them
> generates db/schema.(rb|sql).
>
> * The test environment should always start afresh, the test database is
> considered to be transient by design, gets trashed and rebuilt, and
> therefore has no evolutive maintenance.
>
> * Because of that, the test environment setup is designed around
> db/schema.(rb|sql), not around migrations. You need to get
> db/schema.(rb|sql) right *first*, then run the suite.
>
> * The interface to that workflow is encoded via rake tasks. The test
> environment setup loads the current schema. If you go always through rake
> tasks everything works out of the box as long as the schema is in sync with
> migrations. If it isn't, you need to run migrations in the development
> environment to update the schema (and to have an up to date schema in the
> development database of course).
>
> * If for some reason you prefer not to go through rake tasks for running
> tests, that's a little deviation from the point of view of the Rails
> interface, but the point closer to the golden path is to load the schema by
> hand (db:schema:load), not to run migrations in the test environment.
>
> So, yeah, from my perspective that message is not pointing in the right
> direction.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to