Greg Hauptmann
2008-Sep-05 04:04 UTC
foreign_key_migrations plugin causing incorrect type columns to be created in test database
Just interested if any Rails developers who use foreign_key_migrations have come up against this or not? I''ve just raised this potential issue as a bug on RubyForge http://rubyforge.org/tracker/index.php?func=detail&aid=21823&group_id=1699&atid=6632 ...... I am discovering when I have the redhill forign_key_migrations & core in place, that when I use rails rake tasks for testing that the database field types created in some cases are incorrect, e.g. creating BIGINT as opposed to INT columns, which causes issues when it tries to setup the foreign keys. Note that when: (a) create the test database vi " rake db:migrate RAILS_ENV=''test'' " => This is OK and there are no issues (b) when "rake spec" say uses things such as db:test:purge, db:test:clone, db:schema:load ==> BAD COLUMNS are created. (c) when I delete redhillplugines (core & foreign_key_migrations) & recreate database, I can "rake spec" without an issue More details below: Macintosh:myequity greg$ rails -v Rails 2.1.0 Macintosh:myequity greg$ ruby -v ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin9.3.0] Macintosh:myequity greg$ gem -v 1.2.0 Macintosh:myequity greg$ ================ CASE WHERE ALL IS GOOD =============== Macintosh:myequity greg$ rake db:drop RAILS_ENV="test" mysql> desc transactions; +------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | transaction_date | date | NO | MUL | | | | bank_account_id | int(11) | NO | MUL | | | | category_id | int(11) | YES | MUL | NULL | | | recurring_id | int(11) | YES | MUL | NULL | | | amount | decimal(9,2) | NO | | | | | balance | decimal(9,2) | NO | | | | | description | varchar(255) | YES | | NULL | | | notes | text | YES | | NULL | | | created_at | datetime | YES | | NULL | | | updated_at | datetime | YES | | NULL | | | projection | tinyint(1) | NO | MUL | 0 | | +------------------+--------------+------+-----+---------+----------------+ 12 rows in set (0.01 sec) mysql> desc allocations; +----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | transaction_id | int(11) | NO | MUL | | | | person_id | int(11) | NO | MUL | | | | recurring_id | int(11) | YES | MUL | NULL | | | amount | decimal(9,2) | YES | | NULL | | | amount_percent | decimal(9,2) | YES | | NULL | | | created_at | datetime | YES | | NULL | | | updated_at | datetime | YES | | NULL | | +----------------+--------------+------+-----+---------+----------------+ 8 rows in set (0.01 sec) ========= CASE WHEN THINGS GO WRONG ============== Macintosh:myequity greg$ rake spec --trace (in /Users/greg/source/myequity) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:clone (first_time) ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:clone ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load rake aborted! Mysql::Error: #HY000Can''t create table ''./myequity_test/#sql-83_25e.frm'' (errno: 150): ALTER TABLE allocations ADD CONSTRAINT allocations_ibfk_1 FOREIGN KEY (transaction_id) REFERENCES transactions (id) /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log'' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:299:in `execute'' /Users/greg/source/myequity/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb:34:in `add_foreign_key'' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:330:in `send'' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:330:in `method_missing'' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say_with_time'' /opt/local/lib/ruby/1.8/benchmark.rb:293:in `measure'' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say_with_time'' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:326:in `method_missing'' ./db/schema.rb:182 /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema.rb:43:in `instance_eval'' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema.rb:43:in `define_without_redhillonrails_core'' /Users/greg/source/myequity/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb:19:in `define'' ./db/schema.rb:12 /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in `load'' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in `load'' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in'' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in `load'' /opt/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:226 /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'' /opt/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:271 /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'' /opt/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:343 /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:518:in `invoke_prerequisites'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `send'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:515:in `invoke_prerequisites'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:507:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31 /opt/local/bin/rake:19:in `load'' /opt/local/bin/rake:19 Macintosh:myequity greg$ mysql> mysql> desc transactions; +------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | transaction_date | date | NO | MUL | | | | bank_account_id | bigint(11) | NO | MUL | | | | category_id | bigint(11) | YES | MUL | NULL | | | recurring_id | bigint(11) | YES | MUL | NULL | | | amount | decimal(9,2) | NO | | | | | balance | decimal(9,2) | NO | | | | | description | varchar(255) | YES | | NULL | | | notes | text | YES | | NULL | | | created_at | datetime | YES | | NULL | | | updated_at | datetime | YES | | NULL | | | projection | tinyint(1) | NO | MUL | 0 | | +------------------+--------------+------+-----+---------+----------------+ 12 rows in set (0.05 sec) mysql> desc allocations; +----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | transaction_id | bigint(11) | NO | MUL | | | | person_id | bigint(11) | NO | MUL | | | | recurring_id | bigint(11) | YES | MUL | NULL | | | amount | decimal(9,2) | YES | | NULL | | | amount_percent | decimal(9,2) | YES | | NULL | | | created_at | datetime | YES | | NULL | | | updated_at | datetime | YES | | NULL | | +----------------+--------------+------+-----+---------+----------------+ 8 rows in set (0.01 sec) mysql> ========= WHAT A CALL TO rake spec LOOKS LIKE WITH REDHILL PLUGINS REMOVED ===========Macintosh:plugins greg$ rake spec --trace (in /Users/greg/source/myequity_test1) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:clone (first_time) ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:clone ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute spec Macintosh:plugins greg$ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---