You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# frozen_string_literal: truerequire"bundler/inline"gemfiledosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}gem"rails","7.1.3"# If you want to test against edge Rails replace the previous line with this:# gem "rails", github: "rails/rails", branch: "main"gem"sqlite3"endrequire"active_record"require"minitest/autorun"require"logger"# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedoendclassPost < ActiveRecord::BaseendclassBugTest < Minitest::Testdeftest_index_name_after_rename_table_with_long_table_namelong_table_name="a" * 48migration_class=Class.new(ActiveRecord::Migration[7.0])dodefine_method:migratedo |x|
create_table:postsdo |t|
t.string:titlet.index:titleendrename_table:posts,long_table_nameendendmigration=migration_class.newActiveRecord::Migrator.new(:up,[migration],ActiveRecord::Base.connection.schema_migration,ActiveRecord::Base.connection.internal_metadata).migrateassert_equal"index_#{long_table_name}_on_title",ActiveRecord::Base.connection.indexes(long_table_name).first.nameendend
Expected behavior
The above test should pass.
This means that since the index name was renamed to index_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_on_title in Rails 7.0 and earlier, if ActiveRecord::Migration[7.0] or earlier is specified, the same name should be used even in Rails 7.1 or later.
Actual behavior
The above test fails with the following output:
F
Failure:
BugTest#test_index_name_after_rename_table_with_long_table_name [example.rb:53]:
--- expected
+++ actual
@@ -1 +1 @@
-"index_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_on_title"
+"idx_on_title_0b3d36c24b"
bin/rails test example.rb:32
Finished in 0.026827s, 37.2753 runs/s, 37.2753 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
As a result, if db/migrate contains rename_table, the index names created between Rails 7.0 and 7.1 may be different.
The text was updated successfully, but these errors were encountered:
r7kamura
changed the title
ActiveRecord::MIgration[7.0]'s rename_table uses 7.1's new truncated index name formatActiveRecord::Migration[7.0]'s rename_table uses 7.1's new truncated index name format
Jan 22, 2024
Steps to reproduce
Expected behavior
The above test should pass.
This means that since the index name was renamed to
index_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_on_title
in Rails 7.0 and earlier, ifActiveRecord::Migration[7.0]
or earlier is specified, the same name should be used even in Rails 7.1 or later.Actual behavior
The above test fails with the following output:
As a result, if db/migrate contains
rename_table
, the index names created between Rails 7.0 and 7.1 may be different.System configuration
Rails version: 7.1.3
Ruby version: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
Other information
This is due to the following change:
I think a similar change to the following is needed for
#rename_table
:The text was updated successfully, but these errors were encountered: