mysql - Rails 3 - 尝试创建/迁移空白数据库名称的 Beta 环境

标签 mysql ruby-on-rails ruby-on-rails-3

我的应用程序在开发上运行,我正在尝试将它部署到一个新的切片。该环境称为“测试版”。一切似乎都工作正常,除了 rake 一直试图传递一个空白的 '' 数据库名称,无论是在 capistrano 中调用还是手动调用。我真的很感激任何帮助,因为我不确定下一步该做什么。谷歌搜索没有找到任何结果。

谢谢, rails 上的兔子

ops@rws:~/sites/darkserve/current$ rake db:drop
(in /home/ops/sites/darkserve/releases/20110218183444)
Couldn't drop  : #<ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect database name '': DROP DATABASE IF EXISTS ``>

ops@rws:~/sites/darkserve/current$ rake db:create
(in /home/ops/sites/darkserve/releases/20110218183444)
 already exists

  * executing "cd /home/ops/sites/darkserve/releases/20110218183444; bundle exec rake RAILS_ENV=beta  db:migrate"
    servers: ["173.203.106.112"]
    [173.203.106.112:30000] executing command
*** [err :: 173.203.106.112:30000] rake aborted!
*** [err :: 173.203.106.112:30000] 
*** [err :: 173.203.106.112:30000] Mysql2::Error: No database selected: SHOW TABLES
*** [err :: 173.203.106.112:30000] 
*** [err :: 173.203.106.112:30000] 
*** [err :: 173.203.106.112:30000] (See full trace by running task with --trace)
*** [err :: 173.203.106.112:30000] 
 ** [out :: 173.203.106.112:30000] (in /home/ops/sites/darkserve/releases/20110218183444)

我已经尝试了一些显而易见的事情,比如修改我的 database.yml 和 beta.rb 文件,但都无济于事。 Mysql 正常工作并创建了正确的用户。

common: &mysql
  adapter: mysql2  
  host: localhost
  encoding: utf8
  username: root
  password: 
  pool: 5
  timeout: 5000
  reconnect: true

development:
  <<: *mysql
  database: darkserve_development

test:
  <<: *mysql
  database: darkserve_test

beta:
  <<: *mysql
  database: darkserve_beta

production:
  <<: *mysql
  database: darkserve_prod


ops@rws:~/sites/darkserve/current$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 57
Server version: 5.1.41-3ubuntu12.9 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> 




#beta.rb
Darkserve::Application.configure do
  # Settings specified here will take precedence over those in config/environment.rb

  # The production environment is meant for finished, "live" apps.
  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Specifies the header that your server uses for sending files
  config.action_dispatch.x_sendfile_header = "X-Sendfile"

  # For nginx:
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

  # If you have no front-end server that supports something like X-Sendfile,
  # just comment this out and Rails will serve the files

  # See everything in the log (default is :info)
  # config.log_level = :debug

  # Use a different logger for distributed setups
  # config.logger = SyslogLogger.new

  # Use a different cache store in production
  #config.cache_store = :mem_cache_store

  # Disable Rails's static asset server
  # In production, Apache or nginx will already do this
  config.serve_static_assets = false

  # Enable serving of images, stylesheets, and javascripts from an asset server
  # config.action_controller.asset_host = "http://assets.example.com"

  # Disable delivery errors, bad email addresses will be ignored
  # config.action_mailer.raise_delivery_errors = false
  config.action_mailer.delivery_method = :smtp

  # Enable threaded mode
  # config.threadsafe!

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation can not be found)
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify
end



ops@rws:~/sites/darkserve/current$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
ops@rws:~/sites/darkserve/current$ rails -v
Rails 3.0.4
ops@rws:~/sites/darkserve/current$ irb
ruby-1.9.2-p136 :001 > require 'mysql'
 => true 

最佳答案

我刚换成ruby 1.9,发现了同样的错误。我认为这是 YAML 解析器的错误。扩展引用时似乎无法包含其他键。

考虑以下文件:test.yml

common: &default
  user_name: 'test_user'

failed:
  <<: *default
  database: 'ignored db name'

success:
  user_name: 'test_user'
  database: 'db name'

现在看看您从 ruby​​ 提示中得到了什么:

puts YAML.load_file('test.yml').inspect

{"common"=>{"user_name"=>"test_user"}, "failed"=>{"user_name"=>"test_user"}, 
 "success"=>{"user_name"=>"test_user", "database"=>"db name"}}

要解决此问题,请确保 boot.rb 选择“syck”,我相信这已经存在了一段时间。

require 'rubygems'

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'yaml'
YAML::ENGINE.yamler= 'syck'

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])

关于mysql - Rails 3 - 尝试创建/迁移空白数据库名称的 Beta 环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5045360/

相关文章:

ruby-on-rails - Rails 日志过于冗长

ruby-on-rails-3 - 如何将 "dd.mm.yyyy "字符串转换为日期时间?

mysql - NOLOGGING 不起作用

jquery - 在我的 Rails 3 应用程序中实现 jQuery Masonry 时遇到问题

php - 我的IP是否在我的数据库中,如果有的话找到时间戳

ruby-on-rails - 按子属性对 Activerecord 查询进行分组

ruby-on-rails - Redis服务器重启时如何自动重启Resque worker

ruby-on-rails-3 - Rails SSL 仅在一个特定路径上

mysql - 重命名 mysql 输出

python - 如何使用 SELECT COUNT sql 生成一个 int