Capistrano“上限部署:迁移”失败,因为它尝试运行所有迁移,而不仅仅是待处理的迁移
我尝试使用“cap deploy:migrations”进行部署,因为我有 3 个新的迁移需要在实时服务器上执行。结果是:
executing "cd /home/martin/public_html/project/releases/20110905131238; bundle exec rake RAILS_ENV=production db:migrate"
servers: ["50.56.82.190"]
[50.56.82.190] executing command
** [out :: 50.56.82.190] == CreateUsers: migrating ====================================================
** [out :: 50.56.82.190] -- create_table(:users)
** [out :: 50.56.82.190] rake aborted!
** [out :: 50.56.82.190] An error has occurred, all later migrations canceled:
** [out :: 50.56.82.190]
** [out :: 50.56.82.190] Mysql2::Error: Table 'users' already exists: CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `email` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
** [out :: 50.56.82.190]
** [out :: 50.56.82.190] Tasks: TOP => db:migrate
** [out :: 50.56.82.190] (See full trace by running task with --trace)
command finished in 5816ms
failed: "sh -c 'cd /home/martin/public_html/project/releases/20110905131238; bundle exec rake RAILS_ENV=production db:migrate'" on 50.56.82.190
通过之前的部署,我在实时服务器上创建了一个工作数据库。我创建了 3 个新的迁移(由于使用新的 gems Carrierwave 和 rmagick 上传图像),我现在想部署它们。显然 cap deploy:migrations 尝试从第一个迁移开始运行所有迁移,而不仅仅是待处理的迁移。
我的deploy.rb是:
require 'bundler/capistrano'
set :application, "otg.in"
set :domain, "otg.in"
set :user, "martin"
set :sudo_use, false
set :repository, "[email protected]:Martin118/otg.in.git"
set :local_repository, '~/rails_projects/otg.in/.git'
set :port, 48000
set :deploy_to, "/home/martin/public_html/#{application}"
set :scm, :git
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
server "50.56.82.190", :app, :web, :db, :primary => true
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"
after "deploy:update_code", "deploy:migrate"
after "deploy", "deploy:cleanup"
# Passenger
namespace :deploy do
task :bundle_gems do
run "cd #{deploy_to}/current && bundle install vendor/gems"
end
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
require 'whenever/capistrano'
我运行rails 3.0.8,capdeploy:check给我“你似乎已经安装了所有必要的依赖项”。
有什么想法吗?或者您需要更多信息吗?
感谢您的帮助!
schema.rb 上线是:
ActiveRecord::Schema.define(:version => 20110130000344) do
create_table "businesses", :force => true do |t|
t.string "business_name"
t.string "postal_code"
t.string "business_email"
t.string "phone"
t.string "fax"
t.string "web"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.text "address"
t.integer "city_id"
t.integer "state_id"
end
create_table "cities", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "state_id"
end
create_table "states", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "encrypted_password"
t.string "salt"
t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
end
另一个更新:select * from schema_migrations;我的开发数据库给了我:
+----------------+ |版本 | +----------------+ | 20110112163009 | | 20110113141953 | | 20110113192958 | | 20110114214158 | | 20110115002206 | | 20110119100832 | | 20110120134443 | | 20110127171331 | | 20110127171427 | | 20110127171921 | | 20110127172903 | | 20110127183252 | | 20110129201949 | | 20110129204159 | | 20110129205833 | | 20110130000344 | | 20110808142844 | | 20110809133339 | | 20110809142303 | | 20110809154349 | | 20110810092306 | | 20110810093531 | | 20110812085010 | +----------------+
但是用 MySQL 工作台检查我得到(仍然是开发数据库):
错误:project_development
。schema_migrations
:表数据不可编辑,因为没有为表定义主键
此外,生产数据库上的 schema_migrations 的 select * 只给了我一次迁移(我尝试更新之前的最后一次):
+------ ----------+ |版本 | +----------------+ | 0 | | 20110130000344 | +----------------+
有谁知道这里发生了什么吗?
谢谢!
I try to deploy with "cap deploy:migrations" since I have 3 new migrations which need to be executed on live server. The result is:
executing "cd /home/martin/public_html/project/releases/20110905131238; bundle exec rake RAILS_ENV=production db:migrate"
servers: ["50.56.82.190"]
[50.56.82.190] executing command
** [out :: 50.56.82.190] == CreateUsers: migrating ====================================================
** [out :: 50.56.82.190] -- create_table(:users)
** [out :: 50.56.82.190] rake aborted!
** [out :: 50.56.82.190] An error has occurred, all later migrations canceled:
** [out :: 50.56.82.190]
** [out :: 50.56.82.190] Mysql2::Error: Table 'users' already exists: CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `email` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
** [out :: 50.56.82.190]
** [out :: 50.56.82.190] Tasks: TOP => db:migrate
** [out :: 50.56.82.190] (See full trace by running task with --trace)
command finished in 5816ms
failed: "sh -c 'cd /home/martin/public_html/project/releases/20110905131238; bundle exec rake RAILS_ENV=production db:migrate'" on 50.56.82.190
With a previous deploy I have created a working database on the live server. I created 3 new migrations (due to image upload with new gems carrierwave and rmagick) which I would like to deploy now. Obviously cap deploy:migrations tries to run all migrations from the first one, not just the pending ones.
My deploy.rb is:
require 'bundler/capistrano'
set :application, "otg.in"
set :domain, "otg.in"
set :user, "martin"
set :sudo_use, false
set :repository, "[email protected]:Martin118/otg.in.git"
set :local_repository, '~/rails_projects/otg.in/.git'
set :port, 48000
set :deploy_to, "/home/martin/public_html/#{application}"
set :scm, :git
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
server "50.56.82.190", :app, :web, :db, :primary => true
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"
after "deploy:update_code", "deploy:migrate"
after "deploy", "deploy:cleanup"
# Passenger
namespace :deploy do
task :bundle_gems do
run "cd #{deploy_to}/current && bundle install vendor/gems"
end
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
require 'whenever/capistrano'
I run rails 3.0.8, cap deploy:check gives me "You appear to have all necessary dependencies installed".
Any ideas? Or do you need more information?
Thanks for your help!
schema.rb on live is:
ActiveRecord::Schema.define(:version => 20110130000344) do
create_table "businesses", :force => true do |t|
t.string "business_name"
t.string "postal_code"
t.string "business_email"
t.string "phone"
t.string "fax"
t.string "web"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.text "address"
t.integer "city_id"
t.integer "state_id"
end
create_table "cities", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "state_id"
end
create_table "states", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "encrypted_password"
t.string "salt"
t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
end
Another update: select * from schema_migrations; on my development database gives me:
+----------------+
| version |
+----------------+
| 20110112163009 |
| 20110113141953 |
| 20110113192958 |
| 20110114214158 |
| 20110115002206 |
| 20110119100832 |
| 20110120134443 |
| 20110127171331 |
| 20110127171427 |
| 20110127171921 |
| 20110127172903 |
| 20110127183252 |
| 20110129201949 |
| 20110129204159 |
| 20110129205833 |
| 20110130000344 |
| 20110808142844 |
| 20110809133339 |
| 20110809142303 |
| 20110809154349 |
| 20110810092306 |
| 20110810093531 |
| 20110812085010 |
+----------------+
But checking this with MySQL workbench I get (still development database):
Error: project_development
.schema_migrations
: table data is not editable because there is no primary key defined for the table
Also, the select * from schema_migrations on the productions database gives me just one migration (the last before I try to update):
+----------------+
| version |
+----------------+
| 0 |
| 20110130000344 |
+----------------+
Has anyone an idea what happend here?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是手动将缺少的迁移添加到 schema_migrations 中。不知怎的,这张表似乎丢失了一些数据。无论如何,通过添加已经直接使用“INSERT into schema_migrations(版本)值('2011....');”完成的迁移,然后 cap 部署:迁移从新迁移开始顺利运行。
The solution was to add the missing migrations into schema_migrations by hand. Somehow it seems that this table lost some of it's data. Anyhow, by adding the migrations that have already been done directly with "INSERT into schema_migrations (version) values ('2011....');", then cap deploy:migrations ran smoothly starting with just the new ones.