# Rails 2.0.2 Migration / Migrator issue

**URL:** <https://www.ruby-forum.com/t/rails-2-0-2-migration-migrator-issue/125421>\
**Category:** Rails\
**Created:** [January 8, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/rails-2-0-2-migration-migrator-issue/125421 "2008-01-08T23:22:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 8, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/rails-2-0-2-migration-migrator-issue/125421/1 "2008-01-08T23:22:28Z")

</div>

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 --force

In 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.sqlite3  
> SQLite 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 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.sqlite3  
> SQLite 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
