Capistrano分阶段部署需要全新的数据库迁移 [英] Capistrano Staging Deploy Requires Whole New Database Migration

查看:64
本文介绍了Capistrano分阶段部署需要全新的数据库迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了Capistrano,这样它就可以将Ruby on Rails网站的登台版本成功地从git存储库部署到Amazon服务器.但是,部署后,我必须在服务器上的数据库上运行迁移.如果我不这样做,则无法加载包含登录表单或基于数据库的内容的任何页面.在服务器上运行迁移时,我看到正在迁移的站点上的每个迁移,而不仅仅是最新的迁移.

I have Capistrano set up such that it allows me to deploy the staging version of my Ruby on Rails website to an amazon server from a git repository successfully. However, after deploying, I must run a migration on the database on the server. If I do not, any page with login forms or database-based content cannot load. When I run the migration on the server, I see every singly migration on the site being migrated, not just the most recent ones.

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

I know that Capistrano can maintain the previous migrations, and I thought it did that automatically. My question is, how do stop the apparent database wipe or loss which is occurring so that a migration is only needed if there are actually new migrations?

我在Capistrano输出中没有发现异常错误,并且在Capistrano和数据库方面我是新手.我注意到我的database.yml文件没有用于登台的条目,我想知道它是否可以像添加一个用于数据库设置为db/development.sqlite3的登台条目一样简单?

I see no unusual errors in the Capistrano output and I am a novice when it comes to Capistrano and databases. I noticed that my database.yml file has no entry for staging and I was wondering if it could be as simple as adding an entry for staging with the database set to db/development.sqlite3?

这是我的deploy.rb文件:

here is my deploy.rb file:

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文件:

And my database.yml file:

# 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

Capistrano is not the one that maintains your migration number. rails does. If you want capistrano to run the migrations for you as part of deploy, add this to your config/deploy.rb

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

您可能应该将生产sqlite3文件的位置更改为其他位置,而不是每次部署都将其重写,而不是db/production.sqlite3.像/home/user/production.sqlite3

you should probably have a different location for production sqlite3 file where it will not get rewritten for every deploy, instead of db/production.sqlite3. Something like /home/user/production.sqlite3

这篇关于Capistrano分阶段部署需要全新的数据库迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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