我尝试使用“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, "git@github.com: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,cap deploy: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 workbench 检查这个(仍然是开发数据库):
错误:project_development。schema_migrations:表数据不可编辑,因为没有为表定义主键
另外,生产数据库上的 select * from schema_migrations 只给我一个迁移(我尝试更新之前的最后一个迁移):
+----------------+ |版本 | +----------------+ | 0 | | 20110130000344 | +----------------+
有人知道这里发生了什么吗?
谢谢!
最佳答案
解决方案是手动将缺失的迁移添加到 schema_migrations 中。不知何故,这张表似乎丢失了一些数据。无论如何,通过添加已经使用“INSERT into schema_migrations (version) values ('2011....');”直接完成的迁移,然后 cap deploy:migrations 从新的开始顺利运行。
关于mysql - Capistrano "cap deploy:migrations"失败,因为它尝试运行所有迁移,而不仅仅是挂起的迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7309774/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
如何正确创建Rails迁移,以便将表更改为MySQL中的MyISAM?目前是InnoDB。运行原始执行语句会更改表,但它不会更新db/schema.rb,因此当在测试环境中重新创建表时,它会返回到InnoDB并且我的全文搜索失败。我如何着手更改/添加迁移,以便将现有表修改为MyISAM并更新schema.rb,以便我的数据库和相应的测试数据库得到相应更新? 最佳答案 我没有找到执行此操作的好方法。您可以像有人建议的那样更改您的schema.rb,然后运行:rakedb:schema:load,但是,这将覆盖您的数据。我的做法是(假设
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/