rake db:create failing on Win7 x64 - mysql

Updated to include trace info
I'm setting up a Win7 machine for Ruby on Rails development and seem to have run into an issue with my rake tasks. When I call rake db: create the cmd window sits for a very long time and dumps the following:
C:\my\directory\rails>rake db:create --trace
(in C:/my/directory/rails)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
foo already exists
foo already exists
C:/Ruby192/bin/rake: [BUG] Segmentation fault
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
-- control frame ----------
c:0001 p:0000 s:0002 b:0002 l:000b24 d:000b24 TOP
---------------------------
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
What does this mean? I am running Win7 Pro x64, MySQL 5.5, and Rails 3.

Apparently it was the dll that was faulty. Used this approach.

Related

Rails - how to debug CSS?

My app works fine in development mode, I fail to push in to production however.
This is what I get from RAILS_ENV=production bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}"
(sass):1315
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/scss/parser.rb:1189:in `expected'
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/scss/parser.rb:1125:in `expected'
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/scss/parser.rb:42:in `parse'
/Users/mohnstrudel/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/engine.rb:406:in `_to_tree'
...
buch of lines
By using trial and error I narrowed the suspect down to bootstrap.min.css (it came bundled from template creator, using a plain bootstrap.min.css breaks the design).
Line 1315 and the code around looks like this:
.text-primary {
color: #337ab7
}
a.text-primary:focus,
a.text-primary:hover {
color: #286090 <-- this is exactly line 1315
}
.text-success {
color: #3c763d
}
a.text-success:focus,
a.text-success:hover {
color: #2b542c
}
This error is driving me mad, I can't even figure out what is wrong.
Is there a way to retrieve more informative error message?

Why does Rails say "cannot load such file mysql/mysql_api"?

I was following a tutorial on lynda.com (RoR 3: Section 6, ep. 3) and after installing MySQL and running:
rake db:schema:dump
I got:
rake aborted! cannot load such file mysql/mysql_api
C:/Sites/demo/config/application.rb:7:in '<top <required>>'
C:/Sites/demo/Rakefile:4:in 'require'
C:/Sites/demo/Rakefile:4:in '<top <required>>'
I did copy:
libmySQL.dll
To:
C:\RailsInstaller\Ruby1.9.3\bin
and I also tried uninstalling and installing the mysql gem a couple of times.
I think your problem is similar to cannot load such file -- mysql/mysql_api.
If you are trying to access 64 bit MySQL from 32 bit Ruby then you might encounter this.

can't run migration

I run
rake db:create
and getting strange error
rake aborted!
126: ═х эрщфхэ єърчрээ√щ ьюфєы№. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-
0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so
I tried to reinstall bundler.
Is it gem problem ?
To solve this problem, reference to the following link:
http://maxivak.com/installing-mysql2-gem-on-ruby-1-9-2-and-rails-3-0-5-on-windows/
You need to include mysql-connector through the Rails DevKit.

Unit tests cannot find tables

I'm running unit tests on Rails 2.3 and I keep getting errors along these lines when I run rake test:units:
10) Error:
test_the_truth(BrokerTest):
ActiveRecord::StatementInvalid: Mysql::Error: Table 'shadow_test.users' doesn't exist: DELETE FROM `users`
/Library/Ruby/Gems/1.8/gems/after_commit-1.0.10/lib/after_commit/connection_adapters.rb:14:in `transaction'
I ran rake db:test:load prior to this, and it created the tables. However, when I check mysql after running the unit tests command, the tables are indeed missing. Something in the process of preparing for the unit tests causes the tables to go missing. Here's the debug log from running the test:
WARNING: 'task :t, arg, :needs => [deps]' is deprecated. Please use 'task :t, [args] => [deps]' instead.
at /Users/me/sources/shadow/lib/tasks/turk.rake:53
** Invoke test:units (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:units
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:test" -I"/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib" "/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb"
/Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:211: warning: Insecure world writable dir /usr/local/git/bin in PATH, mode 040777
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Library/Ruby/Gems/1.8/gems/rails-2.3.14/lib/rails/gem_dependency.rb:21.
WARNING: using the built-in Timeout class which is known to have issues when used for opening connections. Install the SystemTimer gem if you want to make sure the Redis client will not hang.
/Users/me/sources/shadow/test/unit/../test_helper.rb:36: warning: already initialized constant BEANSTALK
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Finished in 3.389328 seconds.
Some more background: I'm using Octopus for sharding and that may be somehow interfering with things??
Using the Octopus database sharding gem has a few issues on test case preparation. See GitHub issue: https://github.com/tchandy/octopus/issues/31.
You have a few options, the easiest of which is to disable Octopus for your development environment. Remove "- development" from your shards.yml file.
Otherwise, you can patch the issue by adding task:
task :reconnect_octopus do
if ActiveRecord::Base.connection.is_a?(Octopus::Proxy)
ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end
end
task :'db:test:clone_structure' => :reconnect_octopus
or for Rails 3:
task :reconnect_octopus do
if ActiveRecord::Base.connection.is_a?(Octopus::Proxy)
ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end
end
task :'db:structure:load' => :reconnect_octopus
This should stem off your issue listed above. Happy coding!

db:seed not loading models

I'm trying to seed my database with the standard db/seeds.rb method. This works fine on my development machine, but on my server, I get:
$ sudo rake db:seed RAILS_ENV=production --trace
** Invoke db:seed (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:seed
rake aborted!
uninitialized constant Permission
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing'
/path/.../.../.../.../db/seeds.rb:4
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:215:in `load'
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:215
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
...
But when I check in the console, the model does exist:
$ script/console production
Loading production environment (Rails 2.3.4)
>> Permission
=> Permission(id: integer, ..., created_at: datetime, updated_at: datetime)
What am I forgetting?
In a comment to the blog posted linked to above and here again: http://www.builtfromsource.com/2011/02/09/getting-rake-dbseed-and-config-threadsafe-to-play-nice/
Bruce Adams mentions that one can call:
config.threadsafe! unless $rails_rake_task
to only turn on threadsafe when not running a rake task.
But as the issue is really that threadsafe turns off dependency_loading, you can simply add this line after config.threadsafe! to leave it enabled, but still load your environment as you expect.
config.dependency_loading = true if $rails_rake_task
It can be fixed by disabling threadsafe! in the environment configuration.
I just ran across a good approach to this problem in this article. I'll summarize here so people can (hopefully) find it quicker.
The idea is to turn off threadsafe in the production environment, first by editing config/environments/production.rb:
config.threadsafe! unless ENV['THREADSAFE'] == 'off'
You then set THREADSAFE=off when running rake tasks.