aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb18
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb9
2 files changed, 16 insertions, 11 deletions
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 1d439acb07..02a6da2f71 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -344,13 +344,17 @@ module ActiveRecord
def primary_keys(table_name) # :nodoc:
select_values(<<-SQL.strip_heredoc, "SCHEMA")
- SELECT a.attname FROM pg_index i
- CROSS JOIN generate_subscripts(i.indkey, 1) k
- JOIN pg_attribute a
- ON a.attrelid = i.indrelid
- AND a.attnum = i.indkey[k]
- WHERE i.indrelid = #{quote(quote_table_name(table_name))}::regclass
- AND i.indisprimary
+ SELECT a.attname
+ FROM (
+ SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx
+ FROM pg_index
+ WHERE indrelid = #{quote(quote_table_name(table_name))}::regclass
+ AND indisprimary
+ ) i
+ JOIN pg_attribute a
+ ON a.attrelid = i.indrelid
+ AND a.attnum = i.indkey[i.idx]
+ ORDER BY i.idx
SQL
end
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 657bd43b86..94d63765c9 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -47,17 +47,18 @@ module ActiveRecord
@options = options
end
- # turns 20170404131909 into "2017_04_04131909"
+ # turns 20170404131909 into "2017_04_04_131909"
def formatted_version
- return "" unless @version
stringified = @version.to_s
return stringified unless stringified.length == 14
stringified.insert(4, "_").insert(7, "_").insert(10, "_")
end
- def header(stream)
- define_params = @version ? "version: #{formatted_version}" : ""
+ def define_params
+ @version ? "version: #{formatted_version}" : ""
+ end
+ def header(stream)
stream.puts <<HEADER
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to