Capistrano分段部署需要全新的数据库迁移

我让Capistrano设置为允许我将我的Ruby on Rails网站的暂存版本从git存储库成功部署到amazon服务器。 但是,在部署之后,我必须在服务器上的数据库上运行迁移。 如果不这样做,则无法加载任何包含登录表单或基于数据库的内容的页面。 当我在服务器上运行迁移时,我会看到正在迁移的网站上的每个单独迁移,而不仅仅是最近的迁移。

我知道Capistrano可以保持以前的迁移,我认为它会自动完成。 我的问题是,如何阻止明显的数据库擦除或丢失,以便只有在实际有新的迁移时才需要迁移?

我看到Capistrano输出中没有exception错误,而且对于Capistrano和数据库我是新手。 我注意到我的database.yml文件没有用于登台的条目,我想知道它是否可以像添加数据库设置为db / development.sqlite3的登台条目一样简单?

这是我的deploy.rb文件:

set :application, "staging" set :scm, :git set :repository, "." set :deploy_via, :copy #set :copy_cache, true set :copy_exclude, [".git"] set :user, "username" set :use_sudo, false default_run_options[:pty] = true server "server_url", :app, :web, :db, :primary => true set :deploy_to, "/var/www/staging" # if you want to clean up old releases on each deploy uncomment this: set :keep_releases, 3 after "deploy:restart", "deploy:cleanup" # If you are using Passenger mod_rails uncomment this: namespace :deploy do task :start do ; end task :stop do ; end task :restart, :roles => :app, :except => { :no_release => true } do run "touch #{File.join(current_path,'tmp','restart.txt')}" end end 

和我的database.yml文件:

 # SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000 

Capistrano不是维护您的迁移号码的人。 铁轨呢。 如果您希望capistrano在部署过程中为您运行迁移,请将其添加到您的config / deploy.rb中

 after "deploy:update_code", "deploy:migrate" 

你应该为生产sqlite3文件设置一个不同的位置,它不会为每个部署而不是db / production.sqlite3重写。 像/home/user/production.sqlite3这样的东西