rename_table: table_name_prefix is ignored for target table name #1510

Closed
davidmathei opened this Issue Jun 6, 2011 · 1 comment

Comments

Projects
None yet
3 participants

Tested with rails 3.0.7 on postgres-adapter, but as I see, the code in edge (ActiveRecord::Migration#method_missing) causing the problem is still the same.

To reproduce:

edit config/application.rb:

 config.active_record.table_name_prefix  'pfx_'

generate

rails g migration simple

edit migration:

def self.up
    create_table(:simple) do |t|
        t.timestamps
    end
end

migrate this one, verify that the table in the db is named "pfx_simple"

rename the table:

rails g migration change_it

def self.up
    rename_table :simple, :changed
end

After rake'ing, check the database: (or try to use add_column :changed, :blub , :string ) to see that the table name is now "changed" instead of "pfx_changed"

Culprit is the code in ActiveRecord::Migration#method_missing which says:

      unless arguments.empty? || method == :execute
          arguments[0] = Migrator.proper_table_name(arguments.first)
      end

failing to treat argument[0] with pre- and suffix.

This works (albeit that these kind of comparisons feel itchy):

      unless arguments.empty? || method == :execute
          arguments[0] = Migrator.proper_table_name(arguments.first)
              if method == :rename_table
                  arguments[1] = Migrator.proper_table_name(arguments[1])
              end
      end

as does this in Migration:

rename_table :simple, ActiveRecord::Migrator.proper_table_name(:changed)

tonyc commented Aug 9, 2011

This is also happening on creating tables. I'm getting a double prefix when doing a db:test:prepare

@nashby nashby added a commit to nashby/rails that referenced this issue Nov 26, 2011

@nashby nashby add prefix and suffix to renamed tables, closes #1510 5677f32

tenderlove closed this in 0968ee3 Dec 6, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment