**当我执行“heroku db:push sqlite://mydatabase.db”时,我遇到了 Ruby + Sinatra + Sqlite3 + Heroku 的问题:
当我这样做时:“heroku db:push sqlite://anotador.db”
控制台日志:
2013-01-21T12:37:11+00:00 app[web.1]: Errno::ENOENT - No such file or directory - /app/views/home.erb:
2013-01-21T12:37:11+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:572:in `erb'
我的 anotador.rb :
require 'rubygems'
require 'sinatra'
require 'data_mapper'
DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/anotador.db")
class Nota
include DataMapper::Resource
property :id, Serial
property :content, Text, :required => true
property :complete, Boolean, :required => true, :default => false
property :created_at, DateTime
property :updated_at, DateTime
end
DataMapper.finalize.auto_upgrade!
我的宝石文件:
source :rubygems
gem 'sinatra'
gem 'data_mapper'
gem 'rack-flash'
gem 'sinatra-redirect-with-flash'
gem 'builder'
gem 'dm-postgres-adapter', :group => :production
gem 'dm-sqlite-adapter', :group => :development
gem 'thin'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
在命令行中:
$ bundle
$ git init
$ git add .
$ git commit -m "comentario"
$ heroku create nombreAPP --stack cedar
$ git push heroku master
$ heroku addons:add heroku-postgresql:dev
$ heroku pg:promote <DATABASE_URL>
$ heroku db:push sqlite://anotador.db
我知道 Heroku 不使用 Postgres 和 SQLite
但是 Heroku 有能力移动数据库并使用 SQLite 到 Postgres,在这个链接中举例说明:
https://devcenter.heroku.com/articles/ruby # using-a-sql-database
我在开发中使用 sqlite3,在生产中使用 Postgres
在 GemFile 中:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
这个链接有一个例子:
http://yamilurbina.com/post/4854924459/deploying-a-sinatra-datamapper-sqlite-app-to-heroku