Skip to content

Commit c4957f8

Browse files
authored
Merge pull request rails#28188 from kamipo/use_max_identifier_length_for_index_name_length
Use `max_identifier_length` for `index_name_length`
2 parents 945c3cd + 64e494f commit c4957f8

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Use `max_identifier_length` for `index_name_length` in PostgreSQL adapter.
2+
3+
*Ryuta Kamizono*
4+
15
* Deprecate `supports_migrations?` on connection adapters.
26

37
*Ryuta Kamizono*

activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,6 @@ def extract_foreign_key_action(specifier) # :nodoc:
615615
end
616616
end
617617

618-
def index_name_length
619-
63
620-
end
621-
622618
# Maps logical Rails types to PostgreSQL-specific data types.
623619
def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) # :nodoc:
624620
sql = \

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def initialize(connection, logger, connection_parameters, config)
215215

216216
# @local_tz is initialized as nil to avoid warnings when connect tries to use it
217217
@local_tz = nil
218-
@table_alias_length = nil
218+
@max_identifier_length = nil
219219

220220
connect
221221
add_pg_encoders
@@ -358,8 +358,9 @@ def extensions
358358

359359
# Returns the configured supported identifier length supported by PostgreSQL
360360
def table_alias_length
361-
@table_alias_length ||= query("SHOW max_identifier_length", "SCHEMA")[0][0].to_i
361+
@max_identifier_length ||= select_value("SHOW max_identifier_length", "SCHEMA").to_i
362362
end
363+
alias index_name_length table_alias_length
363364

364365
# Set the authorized user for this session
365366
def session_auth=(user)

activerecord/test/cases/adapters/postgresql/connection_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_table_exists_logs_name
105105
end
106106

107107
def test_table_alias_length_logs_name
108-
@connection.instance_variable_set("@table_alias_length", nil)
108+
@connection.instance_variable_set("@max_identifier_length", nil)
109109
@connection.table_alias_length
110110
assert_equal "SCHEMA", @subscriber.logged[0][1]
111111
end
@@ -177,7 +177,6 @@ def test_reconnection_after_actual_disconnection_with_verify
177177
assert_not_equal original_connection_pid, new_connection_pid,
178178
"umm -- looks like you didn't break the connection, because we're still " \
179179
"successfully querying with the same connection pid."
180-
181180
ensure
182181
# Repair all fixture connections so other tests won't break.
183182
@fixture_connections.each(&:verify!)

0 commit comments

Comments
 (0)