aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2017-02-26 22:38:52 +0000
committerGitHub <noreply@github.com>2017-02-26 22:38:52 +0000
commitc4957f8c540698f44255402c6e1b3398da69c651 (patch)
treeab78de70f49855db9f6192dff6cbef423a65a7b6 /activerecord
parent945c3cd519d8f39d1a4c1e9ea25aa7eb8d975f8e (diff)
parent64e494f7486f0ea6c34707dfe5dd6f19627798af (diff)
downloadrails-c4957f8c540698f44255402c6e1b3398da69c651.tar.gz
rails-c4957f8c540698f44255402c6e1b3398da69c651.tar.bz2
rails-c4957f8c540698f44255402c6e1b3398da69c651.zip
Merge pull request #28188 from kamipo/use_max_identifier_length_for_index_name_length
Use `max_identifier_length` for `index_name_length`
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb5
-rw-r--r--activerecord/test/cases/adapters/postgresql/connection_test.rb3
4 files changed, 8 insertions, 8 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index e74a5775b5..55773f2172 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Use `max_identifier_length` for `index_name_length` in PostgreSQL adapter.
+
+ *Ryuta Kamizono*
+
* Deprecate `supports_migrations?` on connection adapters.
*Ryuta Kamizono*
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index f91547d148..afef0da5c7 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -615,10 +615,6 @@ module ActiveRecord
end
end
- def index_name_length
- 63
- end
-
# Maps logical Rails types to PostgreSQL-specific data types.
def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) # :nodoc:
sql = \
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index db5530f793..bc04565434 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -215,7 +215,7 @@ module ActiveRecord
# @local_tz is initialized as nil to avoid warnings when connect tries to use it
@local_tz = nil
- @table_alias_length = nil
+ @max_identifier_length = nil
connect
add_pg_encoders
@@ -358,8 +358,9 @@ module ActiveRecord
# Returns the configured supported identifier length supported by PostgreSQL
def table_alias_length
- @table_alias_length ||= query("SHOW max_identifier_length", "SCHEMA")[0][0].to_i
+ @max_identifier_length ||= select_value("SHOW max_identifier_length", "SCHEMA").to_i
end
+ alias index_name_length table_alias_length
# Set the authorized user for this session
def session_auth=(user)
diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb
index 98d392f25a..c52d9e37cc 100644
--- a/activerecord/test/cases/adapters/postgresql/connection_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb
@@ -105,7 +105,7 @@ module ActiveRecord
end
def test_table_alias_length_logs_name
- @connection.instance_variable_set("@table_alias_length", nil)
+ @connection.instance_variable_set("@max_identifier_length", nil)
@connection.table_alias_length
assert_equal "SCHEMA", @subscriber.logged[0][1]
end
@@ -177,7 +177,6 @@ module ActiveRecord
assert_not_equal original_connection_pid, new_connection_pid,
"umm -- looks like you didn't break the connection, because we're still " \
"successfully querying with the same connection pid."
-
ensure
# Repair all fixture connections so other tests won't break.
@fixture_connections.each(&:verify!)