Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

freeze gems - supports_migrations? breaks schema_format = :sql

#1931

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

Reported by Doug Sparling · February 10th, 2009 @ 07:28 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:41 PM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:41 PM