对于 Ruby on Rails,如何切换到具有相同 DBMS 或不同 DBMS 的新的空 DB?
如果不需要迁移数据,似乎我们可以编辑database.yml
development:
adapter: mysql
database: myapp_development
host: localhost
username: root
password:
encoding: utf8
1)使用一个全新的数据库,数据为0,只需将第3行更改为:
database: myapp_development_02
然后执行rake db:create
和 rake db:migrate
现在,我们有了一个数据为零的全新数据库?
2) 如果指定使用 SQLite,我们可以将其更改为本文顶部的 MySQL 描述,并执行 rake db:create 和 rake db:migrate< /code>,现在我们有了一个全新的数据库可以使用,是 MySQL 吗?
3) Rails 3 有一个 db/schema.rb。可以用这个代替rake db:migrate
吗?如果有30个迁移文件,则需要30次迁移,但如果使用schema.rb,那么它可以一步到达数据库模式?
4)我认为我们可以在database.yml
文件中创建其他development_02
等,指向旧数据库,或指向不同的DBMS,但只要确保我们运行与
rails ... -e development_02 ...
or
rake ... RAILS_ENV=development_02
?
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_development_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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)