我尝试使用带有nginx,passenger和postresql的ubuntu 16.0.4部署到服务器。现在,当我第一次部署时,它一直工作,直到capistrano运行rake db:migrate。
RBENV_VERSION="2.3.3" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate )
DEBUG [c5c99ee8] == 20160922103610 AddSignToUsers: migrating ===================================
DEBUG [c5c99ee8] -- add_column(:users, :sign, :string)
DEBUG [c5c99ee8] rake aborted!
DEBUG [c5c99ee8] StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "users" does not exist
我明白这是因为我没有创造这些表格。我是capistrano和奇迹的新人。我需要为此编写单独的任务吗?
继承我的deploy.rb
# Change these
server '83.241.146.21', user: 'deploy', roles: %w{app db web}
set :repo_url, 'git@bitbucket.org:gjores/prognoser.git'
set :application, 'prognoser'
# Don't change these unless you know what you're doing
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/deploy/prognoser"
set :ssh_options, {:forward_agent => true}
on :start do
`ssh-add`
end
## Defaults:
# set :scm, :git
# set :branch, :master
# set :format, :pretty
set :log_level, :debug
set :keep_releases, 5
## Linked Files & Directories (Default None):
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
# task :db_schema_load do
# on roles(:db) do
# within release_path do
# with rails_env: (fetch(:rails_env) || fetch(:stage)) do
# execute :rake, 'db:schema:load'
# end
# end
# end
# end
# end
# namespace :deploy do
# desc "Make sure local git is in sync with remote."
# task :check_revision do
# on roles(:app) do
# unless `git rev-parse HEAD` == `git rev-parse origin/master`
# puts "WARNING: HEAD is not the same as origin/master"
# puts "Run `git push` to sync changes."
# exit
# end
# end
# end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart'
invoke 'deploy'
end
end
# desc 'Restart application'
# task :restart do
# on roles(:app), in: :sequence, wait: 5 do
# invoke 'puma:restart'
# end
# end
# before :starting, :check_revision
# after :finishing, :compile_assets
# after :finishing, :cleanup
# after :finishing, :restart
end
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
这是我的capfile
# Load DSL and Setup Up Stages
require 'capistrano/deploy'
require 'capistrano/setup'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
require 'capistrano/rails'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
require 'capistrano/postgresql'
set :rbenv_type, :user
set :rbenv_ruby, '2.3.3'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
# If you are using rvm add these lines:
# require 'capistrano/rvm'
答案 0 :(得分:1)
尝试使用命令加载模式:
RAILS_ENV=production rake db:schema:load