简体   繁体   English

从pgAdmin III运行heroku数据库命令? (哈里的预发射器)

[英]Running a heroku database command from pgAdmin III? (Harry's Prelaunchr)

so i've successfully installed Harrys Prelauncher on Heroku ( https://github.com/harrystech/prelaunchr ) 所以我已经在Heroku( https://github.com/harrystech/prelaunchr )上成功安装了Harrys Prelauncher

and to export my collected emails into a csv i need to run this command (bundle exec rake prelaunchr:create_winner_csvs) 并将我收集的电子邮件导出到csv中,我需要运行以下命令(捆绑exec rake prelaunchr:create_winner_csvs)

is there any way to run that command through pgadmin or some other program? 有什么办法可以通过pgadmin或其他程序运行该命令?

or is the only way for me to download my heroku database and run the command locally? 还是我下载heroku数据库并在本地运行命令的唯一方法? also how and what would i need to do this? 还有,我需要怎么做?

i'm pretty new to rails and postgresql and would really appreciate if someone could help me out! 我是Rails和Postgresql的新手,如果有人可以帮助我,我将不胜感激!

Because the rake task creates files locally you can't just run it on heroku via heroku run rake . 由于rake任务会在本地创建文件,因此您不能仅通过heroku run rake在heroku上运行它。 You can however set up your local database.yml to connect to your heroku postgresql instance and run the rake task locally. 但是,您可以设置本地database.yml以连接到您的heroku postgresql实例并在本地运行rake任务。

  1. Run heroku pg:credentials to get the required database values. 运行heroku pg:credentials以获取所需的数据库值。
  2. Fill in the production environment of config/database.yml with the values you obtained from step 1 (for the value of 'database' in the yml file, use dbnmae from step 1) 使用您从步骤1获得的值填写config/database.yml的生产环境(对于yml文件中“数据库”的值,请使用步骤1中的dbnmae)
  3. Test your connection with RAILS_ENV=production rails db . 使用RAILS_ENV=production rails db测试连接。 This should drop you into a psql console. 这应该使您进入psql控制台。
  4. Run the rake task. 运行rake任务。 RAILS_ENV=production bundle exec rake prelaunchr:create_winner_csvs

The files will save locally in lib/assets as indicated by the documentation. 这些文件将按照文档中的说明本地保存在lib/assets中。

在项目目录中,您可以使用

heroku run rake prelaunchr:create_winner_csvs

You should probably create a UI form in to your application. 您可能应该在应用程序中创建一个UI表单。

On click on export CSV, it should run background job on heroku (Using delayed jobs). 单击导出CSV时,它应在heroku上运行后台作业(使用延迟的作业)。

heroku run rake prelaunchr:create_winner_csvs

Use send_data ruby method. 使用send_data红宝石方法。 To send your generated and dumped data file on to your browser. 将生成和转储的数据文件发送到浏览器。

Download the file on to your local system from running heroku instance. 从运行heroku实例将文件下载到本地系统。

Hope this will resolve your problem. 希望这能解决您的问题。

Cheers!!! 干杯!!!

I ran into this problem recently while developing the Prelaunchr campaign for a client. 我最近在为客户开发Prelaunchr广告系列时遇到了这个问题。 Assuming you have a local version of your app and are using Postgres Copper in Heroku, you can "pull" your Heroku database down to your local machine, set that as your development database in database.yml, and run the rake task from your local app, which should now have the same database as your heroku version. 假设您拥有应用程序的本地版本,并且在Heroku中使用Postgres Copper,则可以将Heroku数据库“拉”到本地计算机,在database.yml中将其设置为开发数据库,​​然后从本地运行rake任务。应用程序,现在应该具有与您的heroku版本相同的数据库。 Here is the command to pull the db (subbing out name_for_database & heroku_app_name with your own): 这是提取数据库的命令(用您自己的数据库减去name_for_database和heroku_app_name):

heroku pg:pull HEROKU_POSTGRESQL_COPPER_URL name_for_database --app heroku_app_name

Make sure to restart your local server to see the new database info populated. 确保重新启动本地服务器以查看填充的新数据库信息。

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

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