For Ruby on Rails, how do you switch to a new and empty DB with the same DBMS or a different DBMS?
If no need to migrate the data, it seems that we can just edit database.yml
development:
adapter: mysql
database: myapp_development
host: localhost
username: root
password:
encoding: utf8
1) to use a brand new db with 0 data, just change the 3rd line to:
database: myapp_developm开发者_开发百科ent_02
and then do a rake db:create
and rake db:migrate
and now, we have a brand new db with zero data?
2) if it was specifying using SQLite, we can just change it to the MySQL description as the top part of this post, and also do a rake db:create
and rake db:migrate
, and now we have a brand new db to work with, and is MySQL?
3) Rails 3 has a db/schema.rb. Can this be used instead of rake db:migrate
, which will involve 30 migrations if there are 30 migration files, but if using schema.rb, then it can reach the database schemas in one step?
4) I think we can create other development_02
, etc, in the database.yml
file, pointing to the old db, or pointing to different DBMS, but just make sure we run with
rails ... -e development_02 ...
or
rake ... RAILS_ENV=development_02
?
- Yes
- Yes
- Yes. In fact, this is the preferred way if you have a big schema.
- Yes. But you'll need to add config/environments/development_02.rb
精彩评论