icn
icn

Reputation: 17876

RAILS_ENV not working properly in command line

I am using rails 5.2.3

Here is my command line

RAILS_ENV=development bundle exec rake db:drop

I was expecting only one development db got dropped. But I got these two dbs got dropped. Something I have missed?

Dropped database 'db/development.sqlite3'
Dropped database 'db/test.sqlite3'

database.yml

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

Upvotes: 0

Views: 816

Answers (2)

DevPro
DevPro

Reputation: 511

Run: bin/rails db:environment:set RAILS_ENV=development

Then run bundle exec rake db:drop

It should only remove dev database ....

Upvotes: 1

asimhashmi
asimhashmi

Reputation: 4378

It's a known issue that when you run db tasks for development environment,they are also run for test envrionemnt.

You can check this issue on the following Rails github reop

https://github.com/rails/rails/issues/27299

As a workaround you can use this:

https://github.com/ioquatix/activerecord-migrations

it fixes some of these issues

Upvotes: 3

Related Questions