rails.stuff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-08 22:21 UTC
Rails 2.0.2 Migration / Migrator issue
Windows XP, Rails 2.0.2, Ruby 1.8.5, sqlite3-ruby (1.2.1), SQLite version 3.3.8 I am hitting the following issue when using the ActiveRecord::Base.table_name_prefix This a basic _out the box_ issue At a command prompt> rails foo > cd foo > ruby script\generate model foo name:string --forceIn an editor add the following to the environment.rb file Rails::Initializer.run do |config| # Lots of stuff # config.active_record.default_timezone = :utc # THIS HERE !! config.active_record.table_name_prefix= ''boo_'' end (Save ...) At the prompt again> rake db:migrate -t > rake db:test:clone -t > sqlite3 db\test.sqlite3SQLite version 3.3.8 Enter ".help" for instructions sqlite> .tables boo_boo_foos boo_boo_schema_info The table names are hosed ... ! Please can anyone help by confirming this problem exists outwith my environment ? The problem is in the active_record/migration file #proper_table_name method which assumes that the table <name> argument is not proper ... The following fixes the problem Create a file config\initializers\migration.rb Copy the following to it require ''active_record/migration'' module ActiveRecord class Migrator#:nodoc: class << self # overide to check for table name propriety def proper_table_name( name ) name.table_name rescue make_proper_table_name( name ) end def make_proper_table_name( name ) is_proper_table_name?( name ) ? name : "#{ActiveRecord::Base.table_name_prefix}#{name}#{ActiveRecord::Base.table_name_suffix}" end def is_proper_table_name?( name ) name_string = name.to_s (not name_string.empty?) and name_string.starts_with? ( "#{ActiveRecord::Base.table_name_prefix}" ) and name_string.ends_with? ( "#{ActiveRecord::Base.table_name_suffix}" ) end end end end (Save ...) Delete the db\*.sqlite3 and db\schema.rb files Then> rake db:migrate > rake db:test:clone > sqlite3 db\test.sqlite3SQLite version 3.3.8 Enter ".help" for instructions sqlite> .tables boo_foos boo_schema_info The tables are as expected. Can anyone confirm this before I take it further. Thanks for all and any help! Cheers! sinclair --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---