ruby heroku_db.rake
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby heroku_db.rake相关的知识,希望对你有一定的参考价值。
require 'csv'
namespace :csv do
# Call like this:
# `rake csv:dump[user@example.com]`
task :dump, [:email] => [:environment] do |t, args|
db_url = Bundler.with_clean_env do
`heroku config:get DATABASE_URL`
end
md = db_url.match(/^postgres:\/\/([^:]+):([^@]+)@([^:]+):(\d+)\/(.+)$/)
production_config = {}
production_config['adapter'] = 'postgresql'
production_config['encoding'] = 'unicode'
production_config['pool'] = 7
production_config['username'] = md[1]
production_config['password'] = md[2]
production_config['host'] = md[3]
production_config['port'] = md[4]
production_config['database'] = md[5]
ActiveRecord::Base.establish_connection(production_config)
# Do something with models, etc.
user = User.find_by_email(args[:email])
# Export jobs
CSV.open('jobs.csv', 'wb') do |csv|
csv << ['id', 'name', 'attention', 'created_at', 'completed_at', 'referrer', 'archived_reason']
user.account.jobs.each do |job|
csv << [
job.id,
job.name,
job.attention,
job.created_at,
job.completed_at,
job.referrer,
job.archived_reason
]
end
end
end
end
以上是关于ruby heroku_db.rake的主要内容,如果未能解决你的问题,请参考以下文章
Ruby运算符
Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速
如何学习ruby?Ruby学习技巧分享
ruby Ruby脚本,看看是否用openssl编译了ruby
什么是ruby?
ruby和ruby ee