diff --git a/lib/pg_ha_migrations/relation.rb b/lib/pg_ha_migrations/relation.rb index 4d4c077..c190046 100644 --- a/lib/pg_ha_migrations/relation.rb +++ b/lib/pg_ha_migrations/relation.rb @@ -107,7 +107,7 @@ def self.from_table_and_columns(table, columns) # modified from https://github.com/rails/rails/pull/47753 if name.bytesize > MAX_NAME_SIZE hashed_identifier = "_#{OpenSSL::Digest::SHA256.hexdigest(name).first(10)}" - description = name.sub("index_#{table.name}_on", "ix_on") + description = name.sub("index_#{table.name}_on", "idx_on") short_limit = MAX_NAME_SIZE - hashed_identifier.bytesize short_description = description.mb_chars.limit(short_limit).to_s diff --git a/spec/safe_statements_spec.rb b/spec/safe_statements_spec.rb index 82a8a86..644482a 100644 --- a/spec/safe_statements_spec.rb +++ b/spec/safe_statements_spec.rb @@ -1832,19 +1832,19 @@ def up end it "generates index name with hashed identifier when default child index name is too large" do - create_range_partitioned_table("x" * 43, migration_klass, with_partman: true) + create_range_partitioned_table("x" * 42, migration_klass, with_partman: true) test_migration = Class.new(migration_klass) do def up - safe_add_concurrent_partitioned_index "x" * 43, :updated_at + safe_add_concurrent_partitioned_index "x" * 42, :updated_at end end allow(ActiveRecord::Base.connection).to receive(:execute).and_call_original aggregate_failures do - expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX "index_#{"x" * 43}_on_updated_at" ON ONLY/).once.ordered - expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX CONCURRENTLY "ix_on_updated_at_\w{10}/).exactly(10).times.ordered + expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX "index_#{"x" * 42}_on_updated_at" ON ONLY/).once.ordered + expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX CONCURRENTLY "idx_on_updated_at_\w{10}/).exactly(10).times.ordered expect(ActiveRecord::Base.connection).to receive(:execute).with(/ALTER INDEX .+\nATTACH PARTITION/).exactly(10).times.ordered end