Environment: Mac OS X 10.5 Rails 2.2.2 (moving up from 2.0.2 -
the few deprecated items have been removed).
When moving to Rails 2.2.2 I decided to freeze gems. It was
after the freeze that I started having trouble generating my test
database structure from a legacy database (no migrations).
I have uncommented
"config.active_record.schema_format = :sql"
in config/environment.rb
What's basically happening is that the
db/development_structure.sql is getting built (when running rake
db:test:clone_structure) but then it dies with an error because it
is trying to use a non-existent schema.rb to build the test
database instead of development_structure.sql.
When I run "rake db:test:clone_structure"
Macintosh:trunk dsparlingimbp$ rake db:structure:dump --trace
(in /Users/dsparlingimbp/Sites/webservice_reg/trunk) Invoke
db:structure:dump (first_time) Invoke environment
(first_time) Execute environment Execute
db:structure:dump rake aborted! Mysql::Error: Table
'uclick_test.schema_migrations' doesn't exist: SELECT version FROM
schema_migrations
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:188:in
log'
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:309:inexecute'
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:301:in
select_rows'
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:27:inselect_values'
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:310:in
dump_schema_information'
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/railties/lib/tasks/databases.rake:288
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/railties/lib/tasks/databases.rake:288:inopen'
/Users/dsparlingimbp/Sites/webservice_reg/trunk/vendor/rails/railties/lib/tasks/databases.rake:288
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in
call'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:inexecute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in
each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:inexecute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in
invoke_with_call_chain'
/usr/local/lib/ruby/1.8/monitor.rb:238:insynchronize'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in
invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:ininvoke'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in
invoke_task'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:intop_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in
each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:intop_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in
standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:intop_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in
run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:instandard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in
run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31
/usr/local/bin/rake:19:inload' /usr/local/bin/rake:19
Running rake db:test:load (development_structure.sql did get
built):
Macintosh:trunk dsparlingimbp$ rake db:test:load (in
/Users/dsparlingimbp/Sites/webservice_reg/trunk) rake aborted! no
such file to load --
/Users/dsparlingimbp/Sites/webservice_reg/trunk/db/schema.rb
So it looks like it's trying to find schema.rb even though I've
set schema_format to sql.
To get by, I commented out:
#if ActiveRecord::Base.connection.supports_migrations?
# File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
#end
in vendor/rails/railties/lib/tasks/databases.rake
I'm using mysql - "supports_migrations?" is set to true in
vendor/rails/activerecord/lib/active_record/connection_adapter/mysql_adapter.rb
def supports_migrations? #:nodoc: true end
Since it assumes supports_migrations? is true based on the fact
I'm using mysql, then dump_schema_information is called:
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
def dump_schema_information #:nodoc:
sm_table = ActiveRecord::Migrator.schema_migrations_table_name
migrated = select_values("SELECT version FROM #{sm_table}")
migrated.map { |v| "INSERT INTO #{sm_table} (version) VALUES ('#{v}');" }.join("\n\n")
end
and here's what causes my error:
migrated = select_values("SELECT version FROM #{sm_table}")
Not sure if this is a bug, or something I've done wrong...it's
only after freezing Rails that I had the problem.
Thanks,
doug sparling