Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your development database is being purged because ActiveRecord::Base.configurations has the test database set to "development.sqlite3". When the rake task is run, the yaml configuration is eval'ed into the ActiveRecord::Base.configurations hash and at that time Rails.env is set to development.</p> <p>If RAILS_ENV=development, the database value for test will be set to</p> <pre><code>database: db/development.sqlite3 </code></pre> <p>or for a different adapter:</p> <pre><code>database: my_app_development </code></pre> <p>You can reproduce this with a simple sqlite only configuration buy changing the test block inside database.yml to the following:</p> <pre><code>test: adapter: sqlite3 database: db/&lt;%= Rails.env %&gt;.sqlite3 pool: 5 timeout: 5000 </code></pre> <p>If you inspect the full ActiveRecord::Base.configurations hash you'll see that test is set to use the development db if no RAILS_ENV is specified. And if you were to specify 'production' or 'staging' it would be set to that. From the console:</p> <pre><code># rails c &gt; ActiveRecord::Base.configurations['test']['database'] =&gt; "db/development.sqlite3" </code></pre> <p>compared with:</p> <pre><code># RAILS_ENV=test rails c &gt; ActiveRecord::Base.configurations['test']['database'] =&gt; "db/test.sqlite3" </code></pre> <p><strong>Update</strong></p> <p>The issue you are seeing with db:reset is also because your yaml file is interpreted once and then the config is set.</p> <p>db:reset will invoke db:drop and db:setup for the given environment. However, if the environment is development, it also does those tasks for the test environment. So it succeeds in dropping for the development environment and then when it executes for test, the database key of the configuration is identical to the development section, hence it can't drop something that no longer exists. Here is what the ActiveRecord::Base.configurations hash looks like when Rails.env == 'development'</p> <pre><code>"development" =&gt; { "adapter" =&gt; "sqlite3", "database" =&gt; "db/development.sqlite3", "pool" =&gt; 5, "timeout" =&gt; 5000 }, "test" =&gt; { "adapter" =&gt; "sqlite3", "database" =&gt; "db/development.sqlite3", "pool" =&gt;5, "timeout"=&gt;5000 }, "production" =&gt; { "adapter" =&gt; "sqlite3", "database" =&gt; "db/development.sqlite3", "pool"=&gt;5, "timeout"=&gt;5000 } </code></pre> <p>And once it's in that hash, it doesn't go back and re-read the database.yml file. That hash is what is generated given this <strong>database.yml</strong></p> <pre><code>development: adapter: sqlite3 database: db/&lt;%= Rails.env %&gt;.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 database: db/&lt;%= Rails.env %&gt;.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/&lt;%= Rails.env %&gt;.sqlite3 pool: 5 timeout: 5000 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload