rake failing after deleting database or database tables

3 views
Skip to first unread message

belliappa

unread,
Sep 3, 2008, 6:54:52 PM9/3/08
to Thinking Sphinx
Hello Pat,

I've been using TS v0.9.5 as a plugin and it has been working fine,
until I updated to the trunk (needed the multi model feature).

Running the "rake db:create" command results in TS attempting to
access the database. Seems like something in the TS bootstrap process
is attempting to access the database. This did not occur in v0.9.5.
Even "rake -T" failed.

Just to verify that it was an issue with the latest TS update, I
reverted back to v0.9.5, created the database, ran rake db:migrate
successfully, then upgraded plugin to the TS trunk, did not get any
errors when executing "rake -T"

Please let me know where I might submit this error and if there is any
accompanying information you would like me to add to this post.

Thank you.

Bell

Wolf

unread,
Sep 16, 2008, 2:35:21 AM9/16/08
to Thinking Sphinx
Hi Bell,

my guess is, you access the DB in a method running while class
initialisation, like acts_as_xxx.
The newer version of TS instantiates every indexed class and thereby
invokes those methods.
The only solution for me was to remove the DB access.

regards,
Wolf

Pat Allan

unread,
Sep 29, 2008, 2:18:18 AM9/29/08
to thinkin...@googlegroups.com
Hi Bell

Just tested this with the latest version of TS, and can't get any
errors happening... created a new rails app, generated a model, added
a basic sphinx index to the model, ran db:create, ran db:migrate - all
worked fine...

Not sure if this is due to a recent change, or if I'm doing something
a bit different to your situation...

Cheers

--
Pat

Vin

unread,
Oct 5, 2008, 11:07:08 AM10/5/08
to Thinking Sphinx
Pat,
I'm having the same issues as Bell. Cannot run db:migrate on empty
database with latest version, but works fine if I revert to 0.95
version. Is there a fix for this on any other branch.

Thanks
-Vin

Wolf

unread,
Oct 5, 2008, 1:55:35 PM10/5/08
to Thinking Sphinx
I'm pretty sure the problem is similar to the one I wrote about
earlier.
Are you using plugins which somehow access the DB when they are added
to the class through e.g. acts_as_xyz ?
When you rake with full trace, where does the error occur?

regards,
Wolf

Vin

unread,
Oct 5, 2008, 2:42:19 PM10/5/08
to Thinking Sphinx
Hi Wolf,

If I run the command
> rake environment RAILS_ENV=production db:create -v -t

I get the following errors.

Also could you please elaborate plugins which somehow access the DB
when they are added to the class thorugh e.g. acts_as_xyz, so I can
properly check the plugins.

I don't see above mentioned dependency in the plugins. The other think
I'm confused is how come this plugin dependency was not any issue with
previous version of TS v0.95?

Error:--------------------------------
Unknown database 'db_production'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
connection_adapters/mysql_adapter.rb:527:in
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
base.rb:1149:in `columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
base.rb:1157:in `columns_hash'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
base.rb:1207:in `descends_from_active_record?'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/lib/thinking_sphinx/index.rb:270:in `initialize_from_builder'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/lib/thinking_sphinx/index.rb:39:in `initialize'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/lib/thinking_sphinx/active_record.rb:68:in `new'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/lib/thinking_sphinx/active_record.rb:68:in `define_index'
/home/vinb/dev/rails/production/mypromos/app/models/all_person.rb:32
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:510:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:355:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:510:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:102:in `require_or_load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:261:in `load_missing_constant'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:468:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:480:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
inflector.rb:285:in `constantize'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
inflector.rb:284:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
inflector.rb:284:in `constantize'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
core_ext/string/inflections.rb:143:in `constantize'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/lib/thinking_sphinx/configuration.rb:174:in `load_models'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/lib/thinking_sphinx/configuration.rb:165:in `each'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/lib/thinking_sphinx/configuration.rb:165:in `load_models'
/home/vinb/dev/rails/production/mypromos/vendor/plugins/thinking-
sphinx/init.rb:5:in `evaluate_init_rb'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:177:in `call'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:177:in `evaluate_method'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:161:in `call'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:90:in `run'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:90:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:90:in `send'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:90:in `run'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
callbacks.rb:272:in `run_callbacks'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/initializer.rb:493:in
`send'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/initializer.rb:493:in
`prepare_dispatcher'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/initializer.rb:155:in
`process'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/initializer.rb:97:in
`send'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/initializer.rb:97:in `run'
/home/vinb/dev/rails/production/mypromos/config/environment.rb:13
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:510:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:355:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:510:in `require'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/tasks/misc.rake:3
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:621:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:621:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:616:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:616:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:582:in
`invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:575:in
`invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:568:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2031:in
`invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2048:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2003:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:1982:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2048:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:1979:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/bin/rake:31
/usr/bin/rake:19:in `load


Let me know if I'm looking in the wrong direction, as I'm sort of a
noobie in this area.

regrad
-Vin

Vin

unread,
Oct 5, 2008, 3:09:06 PM10/5/08
to Thinking Sphinx
Hi Wolf,

Sorry for pulling the trigger on reply early.
There is one issue which I found fixed the error and I don't know much
to explain the reason. Here's the scenario

I've actvierecord inheritance model which I derive from other active
record.
e.g.
class B < A{
define_index do
indexes [screen_name], :as => :screen_name, :sortable =>
true, :infixes => true
indexes [first_name, last_name], :as => :name, :sortable => true
set_property :field_weights => {"screen_name" => 100, :name =>
60, :description => 40}
end
}

class A {

define_index do
indexes [screen_name], :as => :screen_name, :sortable =>
true, :infixes => true
indexes [description], :as => :description, :sortable => true
indexes [first_name, last_name], :as => :name, :sortable => true
where "some_condition"
set_property :field_weights => {"screen_name" => 100, :name =>
60, :description => 40}
end
}

now both B and A active records have same define_index definition,
except there is "where " condition in the base active record A.
Somehow db:create migrtation fails at the definition of
"define_index do" in class B.

If I remove define_index from derived class, everything works fine,
i.e., once I remove the ineheritance relationship everything works
fine.

My question is there index class dependency between derived or parent
class; or each active record define_index is independent of
inheritance relationship? I would think looking at the config that
they are independent. I'm confused how TS handles inheritance
relationship, when both parent and child have index defined?

regards
-Vin

Wolf

unread,
Oct 5, 2008, 7:25:22 PM10/5/08
to Thinking Sphinx
Ok, it's not another plugin which uses the DB on initializing but TS
itself.

TS uses the method "descends_from_active_record?" on the model which
asks the DB for the hash of columns which fails, if there isn't a
table yet.
By removing your index definition on the inherited class, that method
isn't called and the rake task can continue.

A workaround for your case, until this issue is fixed, would be to
remove the inhertitance then call rake db:create and put the
inheritance back in again afterwards.

regards,
Wolf

Pat Allan

unread,
Oct 6, 2008, 2:05:14 AM10/6/08
to thinkin...@googlegroups.com
Ah, so it's from an STI setup... right, now I have something more
concrete to test with, will try and make the code smarter.

Cheers

--
Pat

Pat Allan

unread,
Oct 6, 2008, 2:08:51 AM10/6/08
to thinkin...@googlegroups.com
Hi Vin

If you have an STI setup like below, the parent's index is shared with
the child class. Which means that the index defined in B is an
additional one... and I'll say right now that multiple indexes for a
single model needs some work (I need to clear up what Sphinx requires,
and then make sure the code enforces that).

As for the db:create thing, I'll try to get a patch sorted soon -
ideally this week.

Cheers

--
Pat

Vin

unread,
Oct 6, 2008, 5:46:05 PM10/6/08
to Thinking Sphinx
Hi pat,

Thanks for the upcoming fix; I'm looking forward to it - as it's a
pain to remove and added indexes to work around migrations. Your fix
will help keep things transparent and automated thanks again.

-Vin

Pat Allan

unread,
Oct 11, 2008, 2:20:42 AM10/11/08
to thinkin...@googlegroups.com
Hey Vin

Patch is in and pushed to GitHub - was all of one line, in the end.

Cheers

--
Pat

Vin

unread,
Oct 12, 2008, 1:40:04 AM10/12/08
to Thinking Sphinx
Hi Pat,
Thanks for the fix and your efforts.
I checked the latest version and looks like "db:create" passes without
any problems, but db:migration still has problems. If I use the same
workaround, my db:migration works. In short db:create worked, but
still failing on db:migration call.

-Vin

Pat Allan

unread,
Oct 12, 2008, 1:58:38 AM10/12/08
to thinkin...@googlegroups.com
And I've just found that the patch causes some serious problems... so
it's going to have to change, but for the moment, I'm afraid it's
going to be removed.

Sorry. And for anyone who's updated in the last 24 hours or so, I
recommend you update again now!

--
Pat

Pat Allan

unread,
Oct 12, 2008, 4:39:32 AM10/12/08
to thinkin...@googlegroups.com
And a new fix is now live - not quite so neat, but it lets you define
indexes on models, which is kinda important ;)

--
Pat

Pat Allan

unread,
Oct 12, 2008, 9:12:17 AM10/12/08
to thinkin...@googlegroups.com
Hi Vin

Shame it's not quite working. Could you send me the trace from rake
db:migrate so I can see where the problem is?

Cheers

--
Pat

Vin

unread,
Oct 12, 2008, 10:53:05 AM10/12/08
to Thinking Sphinx
Pat,
Will be pleased to send the trace.

I add a comment in the trace ====> My commnent where my code is called
to the derived activerecord and the line points to index definition.
Here it is:::

vin@ubuntu-ws:~/dev/rails/myapp$ rake db:migrate --trace
(in /home/vin/dev/rails/myapp)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql::Error: Table 'db_dev.people' doesn't exist: SHOW FIELDS FROM
`people`
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
connection_adapters/abstract_adapter.rb:147:in `log'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
connection_adapters/mysql_adapter.rb:302:in `execute'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
connection_adapters/mysql_adapter.rb:433:in `columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
base.rb:1149:in `columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
base.rb:1157:in `columns_hash'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/
base.rb:1207:in `descends_from_active_record?'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/lib/
thinking_sphinx/index.rb:272:in `initialize_from_builder'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/lib/
thinking_sphinx/index.rb:39:in `initialize'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/lib/
thinking_sphinx/active_record.rb:68:in `new'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/lib/
thinking_sphinx/active_record.rb:68:in `define_index'
/home/vinb/dev/rails/mypromos/app/models/all_person.rb:32 (====> My
commnent - this is the derived activerecord from base class person as
I mentioned earlier in my exapmle of class A and B)
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:216:in `load_without_new_constant_marking'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:216:in `load_file'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:355:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:215:in `load_file'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:96:in `require_or_load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:261:in `load_missing_constant'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:468:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:480:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
inflector.rb:285:in `constantize'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
inflector.rb:284:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
inflector.rb:284:in `constantize'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
core_ext/string/inflections.rb:143:in `constantize'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/lib/
thinking_sphinx/configuration.rb:174:in `load_models'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/lib/
thinking_sphinx/configuration.rb:165:in `each'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/lib/
thinking_sphinx/configuration.rb:165:in `load_models'
/home/vinb/dev/rails/mypromos/vendor/plugins/thinking-sphinx/init.rb:
/home/vinb/dev/rails/mypromos/config/environment.rb:13
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:510:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:355:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/
dependencies.rb:510:in `require'
/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/tasks/misc.rake:3
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:621:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:621:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:616:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:616:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:582:in
`invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:575:in
`invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:592:in
`invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:589:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:589:in
`invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:581:in
`invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:575:in
`invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:568:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2031:in
`invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2009:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2048:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2003:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:1982:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:2048:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/lib/rake.rb:1979:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.2/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19


Hope this helps
-Vin



Vin

unread,
Oct 15, 2008, 9:55:54 AM10/15/08
to Thinking Sphinx
Pat,
Any word on a quick fix for the above issue?

Thanks
-Vin

Pat Allan

unread,
Oct 26, 2008, 6:44:37 AM10/26/08
to thinkin...@googlegroups.com
Hi Vin

I've tried again, and I can't reproduce this bug using the latest
version of Thinking Sphinx and Rails 2.1.1. If I force Rails to throw
the same error, it turns out it's not an instance of Mysql::Error, but
ActiveRecord::StatementInvalid - but I'm catching both of those in
Thinking Sphinx now (have been since I last tried to fix this, and we
got past db:create). So I'm a bit confused as to why it's still
happening...

If you're still having the problem, let me know.

Cheers

--
Pat

Reply all
Reply to author
Forward
0 new messages