Skip to content

Commit

Permalink
Merge pull request #10798 from jcxplorer/fix-enable_extension-with-ta…
Browse files Browse the repository at this point in the history
…ble_name_prefix

Fix migrations that use enable_extension with table_name_prefix/suffix

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/migration.rb
  • Loading branch information
rafaelfranca committed May 19, 2014
2 parents 4273554 + 40708c3 commit 889f61e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Fix bug that added `table_name_prefix` and `table_name_suffix` to
extension names in PostgreSQL when migrating.

*Joao Carlos*

* The `:index` option in migrations, which previously was only available for
`references`, now works with any column types.

Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def method_missing(method, *arguments, &block)

say_with_time "#{method}(#{arg_list})" do
unless @connection.respond_to? :revert
unless arguments.empty? || method == :execute
unless arguments.empty? || [:execute, :enable_extension, :disable_extension].include?(method)
arguments[0] = proper_table_name(arguments.first, table_name_options)
arguments[1] = proper_table_name(arguments.second, table_name_options) if method == :rename_table
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require "cases/helper"
require "active_record/base"
require "active_record/connection_adapters/postgresql_adapter"

class PostgresqlExtensionMigrationTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false

class EnableHstore < ActiveRecord::Migration
def change
enable_extension "hstore"
end
end

class DisableHstore < ActiveRecord::Migration
def change
disable_extension "hstore"
end
end

def setup
super

@connection = ActiveRecord::Base.connection

unless @connection.supports_extensions?
return skip("no extension support")
end

ActiveRecord::Base.table_name_prefix = "p_"
ActiveRecord::Base.table_name_suffix = "_s"
ActiveRecord::SchemaMigration.delete_all rescue nil
ActiveRecord::Migration.verbose = false
end

def teardown
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
ActiveRecord::SchemaMigration.delete_all rescue nil
ActiveRecord::Migration.verbose = true

super
end

def test_enable_extension_migration_ignores_prefix_and_suffix
@connection.disable_extension("hstore")

migrations = [EnableHstore.new(nil, 1)]
ActiveRecord::Migrator.new(:up, migrations).migrate
assert @connection.extension_enabled?("hstore"), "extension hstore should be enabled"
end

def test_disable_extension_migration_ignores_prefix_and_suffix
@connection.enable_extension("hstore")

migrations = [DisableHstore.new(nil, 1)]
ActiveRecord::Migrator.new(:up, migrations).migrate
assert_not @connection.extension_enabled?("hstore"), "extension hstore should not be enabled"
end
end

0 comments on commit 889f61e

Please sign in to comment.