简体   繁体   English

Ruby on Rails:开发与生产数据库-在哪里输入数据?

[英]Ruby on Rails : Development vs Production database - where to enter data?

I'm very new to Rails. 我是Rails的新手。

I am confused about the development and production databases. 我对开发和生产数据库感到困惑。 I am using postgreSQL for all of my environments and heroku to host the site. 我正在所有环境中使用postgreSQL,并在heroku中托管该网站。 I am able to push migrations and seeds to my production database on heroku. 我能够将迁移和种子推送到heroku上的生产数据库中。 However I entered quite a bit of new data through the browser on localhost:3000. 但是,我通过localhost:3000上的浏览器输入了很多新数据。 I spent a long time trying to figure out how to get that data to heroku but finally was successful by destroying then creating a new empty database and pushing my development database to it. 我花了很长时间试图弄清楚如何将这些数据发送到heroku,但最终成功了,方法是销毁然后创建一个新的空数据库并将开发数据库推入该数据库。 Now my site on heroku is the same as localhost:3000 using rails server. 现在我在heroku上的站点与使用Rails服务器的localhost:3000相同。 I modified the database.yaml file so that the development and production databases are now the same name (the name of the development database). 我修改了database.yaml文件,以便开发和生产数据库现在具有相同的名称(开发数据库的名称)。 But I don't think that means that if I make changes to the development database through localhost:3000 they will automatically be changed on the heroku site. 但是我不认为这意味着如果我通过localhost:3000对开发数据库进行更改,它们将在heroku站点上自动更改。 I am very confused about the colors (CRIMSON, MAROON) on heroku - are those different databases than what I specify in the yaml? 我对heroku上的颜色(CRIMSON,MAROON)非常困惑-这些数据库与我在yaml中指定的数据库不同吗? And I don't know whether I should now be entering new data on the localhost:3000 site or the heroku site. 而且我不知道我现在是否应该在localhost:3000站点或heroku站点上输入新数据。 Sorry if this is very amateur. 抱歉,这是非常业余的。 Thank you. 谢谢。

You're getting confused with how Rails uses Databases 您对Rails如何使用数据库感到困惑

Let me explain: 让我解释:


Rails uses the MVC (Model View Controller) programming pattern to populate your applications with database data. Rails使用MVC(模型视图控制器)编程模式来用数据库数据填充应用程序。 Rails uses this pattern because it's the most efficient & extensible, and it works by taking a command from a user (clicks a link, inputs data), sends to the controller & performs the request on the model Rails使用此模式是因为它是最有效和可扩展的,并且可以通过接受用户的命令来工作(单击链接,输入数据),发送给控制器并在模型上执行请求

The way all rails applications work is to take commands (which you define), and perform database operations with them & then repopulates the app with the new data 所有Rails应用程序的工作方式是接受命令(您定义的),并使用它们执行数据库操作,然后用新数据重新填充应用程序

Rails is designed to work with a single database, and the database.yml file is there to specify which database that is (it's good practice to have different databases for development, staging & production -- for performance, efficiency & other issues) Rails旨在与单个数据库一起使用,并且在那里使用database.yml文件指定哪个数据库(对于性能,效率和其他问题,具有用于开发,登台和生产的不同数据库是一个好习惯)

This means that the database name is not important - what is important is to keep both databases up to date using the rake db:migrate system to give all databases the required columns to make your app work properly 这意味着该数据库的名称并不重要-重要的使用,以保持这两个数据库最新rake db:migrate系统给所有数据库所需的列,使您的应用程序正常工作


In answer to your question, the data you have is going to be different for development & production. 为了回答您的问题,开发和生产中使用的数据将有所不同。 Your production environment is meant to be that "holy-of-holies" where everything is compiled & running efficiently 您的生产环境就是“圣洁”,所有内容都可以有效地编译和运行

The production environment is meant to handle its own data, and should be populated through your application. 生产环境旨在处理自己的数据,并且应通过您的应用程序进行填充。 The reason for development & production databases is to ensure you can "get things wrong" in the development environment before you try and apply it to the production db 开发和生产数据库的原因是要确保在尝试将其应用到生产数据库之前,可以在开发环境中“弄错”。

If you tell us some more about your specific issues, we'll be able to give a much more refined answer 如果您告诉我们更多有关您的特定问题的信息,我们将给出更详尽的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM