Skip to content

Commit

Permalink
Merge pull request #28293 from kamipo/remove_useless_migrator_schema_…
Browse files Browse the repository at this point in the history
…migrations_table_name

Remove useless `Migrator.schema_migrations_table_name`
  • Loading branch information
eileencodes committed Mar 5, 2017
2 parents 6ef074a + 60440a6 commit 45b64bb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Expand Up @@ -996,7 +996,7 @@ def dump_schema_information #:nodoc:
end

def insert_versions_sql(versions) # :nodoc:
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)

if versions.is_a?(Array)
sql = "INSERT INTO #{sm_table} (version) VALUES\n"
Expand Down Expand Up @@ -1025,7 +1025,7 @@ def internal_string_options_for_primary_key # :nodoc:
def assume_migrated_upto_version(version, migrations_paths)
migrations_paths = Array(migrations_paths)
version = version.to_i
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)

migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
versions = ActiveRecord::Migrator.migration_files(migrations_paths).map do |file|
Expand Down
6 changes: 1 addition & 5 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -1022,12 +1022,8 @@ def open(migrations_paths)
new(:up, migrations(migrations_paths), nil)
end

def schema_migrations_table_name
SchemaMigration.table_name
end

def get_all_versions(connection = Base.connection)
if connection.table_exists?(schema_migrations_table_name)
if SchemaMigration.table_exists?
SchemaMigration.all.map { |x| x.version.to_i }.sort
else
[]
Expand Down
10 changes: 5 additions & 5 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -337,20 +337,20 @@ def migrate(x)
end

def test_schema_migrations_table_name
original_schema_migrations_table_name = ActiveRecord::Migrator.schema_migrations_table_name
original_schema_migrations_table_name = ActiveRecord::Base.schema_migrations_table_name

assert_equal "schema_migrations", ActiveRecord::Migrator.schema_migrations_table_name
assert_equal "schema_migrations", ActiveRecord::SchemaMigration.table_name
ActiveRecord::Base.table_name_prefix = "prefix_"
ActiveRecord::Base.table_name_suffix = "_suffix"
Reminder.reset_table_name
assert_equal "prefix_schema_migrations_suffix", ActiveRecord::Migrator.schema_migrations_table_name
assert_equal "prefix_schema_migrations_suffix", ActiveRecord::SchemaMigration.table_name
ActiveRecord::Base.schema_migrations_table_name = "changed"
Reminder.reset_table_name
assert_equal "prefix_changed_suffix", ActiveRecord::Migrator.schema_migrations_table_name
assert_equal "prefix_changed_suffix", ActiveRecord::SchemaMigration.table_name
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
Reminder.reset_table_name
assert_equal "changed", ActiveRecord::Migrator.schema_migrations_table_name
assert_equal "changed", ActiveRecord::SchemaMigration.table_name
ensure
ActiveRecord::Base.schema_migrations_table_name = original_schema_migrations_table_name
Reminder.reset_table_name
Expand Down

1 comment on commit 45b64bb

@jasnow
Copy link

@jasnow jasnow commented on 45b64bb Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Know this in not part of rails repo, but lots of people use database_cleaner.
Regression: DatabaseCleaner/database_cleaner#476
PR: DatabaseCleaner/database_cleaner#477

Please sign in to comment.