对于 Ruby on Rails,如何切换到具有相同 DBMS 或不同 DBMS 的新的空 DB?

发布于 2024-09-24 13:28:48 字数 860 浏览 1 评论 0原文

如果不需要迁移数据,似乎我们可以编辑database.yml

development:
  adapter: mysql
  database: myapp_development
  host: localhost
  username: root
  password:
  encoding: utf8

1)使用一个全新的数据库,数据为0,只需将第3行更改为:

database: myapp_development_02

然后执行rake db:createrake 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心不设防 2024-10-01 13:28:48
  1. 是的
  2. 的 是的。事实上,如果您有一个大架构,这是首选方法。
  3. 是的。但您需要添加 config/environments/development_02.rb
  1. Yes
  2. Yes
  3. Yes. In fact, this is the preferred way if you have a big schema.
  4. Yes. But you'll need to add config/environments/development_02.rb
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文