Rails:使用development.sqlite3数据填充Heroku数据库 [英] Rails: Populate Heroku database with development.sqlite3 data

查看:164
本文介绍了Rails:使用development.sqlite3数据填充Heroku数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不会问这是否我的特殊情况已经在这个论坛上回答,所以请原谅我重新问。



我有一个rails应用程序,它使用sqlite3数据库进行开发,它已经包含我需要的应用程序的所有数据。在将此应用推送到heroku时,我无法在那里查看应用,直到我不得不运行heroku运行rake db:migrate。现在我可以查看该应用了,但我无法使用管理员帐户登录或执行任何其他需要数据库数据的事情。我已经做了所有必要的(我认为),如下面我的gem文件所示:

  source'https:// ruby​​gems .org'

gem'rails','3.2.12'
gem'bcrypt-ruby'
gem'kaminari'
gem'gon'



gem'jquery-rails','2.0.2'

group:development,:test do
gem'sqlite3','1.3.7'
end

组:生产do
gem'pg','0.12.2'
结束


我也尝试过heroku db:push,但这也没有帮助。主要问题是我正在与其他人一起开发这个应用程序,并且我们使用github进行版本控制。但是每当我们获得更新时,我们的sqlite数据库似乎总是自行清空。因此,为了解决这个问题,我们通常必须将更新后的数据库直接发送给其他人,然后他们继续使用它并替换他本地回购中的空白。我怀疑为什么heroku rakedb:迁移是这样的。



但是,随着我们在我们的发展中走到这一步,我们实在无法重新开始。有没有办法让我们的本地repo数据库的内容填充远程heroku数据库?感谢您的回应 您应该将您的数据从sqlite导出到sql转储文件并开始在本地使用postgres。如果你继续在本地使用sqlite并且远程postgres,你将会有一段糟糕的时间。



在您本地迁移后,请按照用PG备份导入和导出Heroku Postgres数据库。

另外,不要使用 db:推 db:pull ;它们已被弃用。


更新



postgres,首先安装并设置postgres(Homebrew,macports, other ...)然后执行如下操作:

  $ psql -U user -d database< file.sql 

从那里开始,您可以使用 pg_dump 实用程序导出到 .dump 文件。你也可以直接将sql导入到Heroku Postgres中:

 #这将删除postgres中的所有数据,因此请确保它是你想要
$ heroku pg:reset HEROKU_POSTGRESQL_COLOR --app app_name
$ heroku pg:psql HEROKU_POSTGRESQL_COLOR --app app_name< file.sql


I would not ask this if my peculiar case had already been answered on this forum so please pardon my re-asking.

I have a rails app which uses an sqlite3 database for development and it already contains all the data I need for the app. On pushing this app to heroku I was unable to view the app over there until I had to run heroku run rake db:migrate. Now I can view the app, but I can't login in with admin accounts or do any other thing that requires data from the database. i already did all that is required (I think) as shown in my gem file below:

    source 'https://rubygems.org'

gem 'rails', '3.2.12'
gem 'bcrypt-ruby'
gem 'kaminari'
gem 'gon'
.
.
.
gem 'jquery-rails', '2.0.2'

group :development, :test do
  gem 'sqlite3', '1.3.7'
end

group :production do
  gem 'pg', '0.12.2'
end
.
.

I also tried heroku db:push but that didn't help either. The main issue is that i am working on this app with someone else and we employ github for version control. But whenever I we get updates form each other our sqlite database always seems to empty itself. So to solve this problem we usually have to email the updated database directly to the other, who then proceeds to use it and replace the empty on in his local repo. I suspect that the reason why heroku rakedb:migrate is this.

But giving as we've come this far in our development, we really cannot afford to start over. Is there a way we can populate the remote heroku database with the content of our local repo db? Thanks for your responses

解决方案

You should export your data from sqlite into a sql dump file and start using postgres locally. If you continue to use sqlite locally and postgres remotely, you will have a bad time.

After you've migrated locally, follow this guide on Importing and Exporting Heroku Postgres Databases with PG Backups.

Also, don't use db:push or db:pull; they are deprecated.

Update

To get the sql file in your local postgres, first install and setup postgres (Homebrew, macports, other...) then do something like so:

$ psql -U user -d database < file.sql

From there, you can use the pg_dump utility to export to a .dump file. You can also import the sql directly to Heroku Postgres:

# this will delete ALL data in your postgres, so make sure it's what you want
$ heroku pg:reset HEROKU_POSTGRESQL_COLOR --app app_name
$ heroku pg:psql HEROKU_POSTGRESQL_COLOR --app app_name < file.sql

这篇关于Rails:使用development.sqlite3数据填充Heroku数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆