aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
diff options
context:
space:
mode:
authorKir Shatrov <shatrov@me.com>2016-11-10 20:50:45 -0500
committerKir Shatrov <shatrov@me.com>2016-11-11 11:02:58 -0500
commit3dce96a6b1242452860e3a9560ccfb357cede0b1 (patch)
treee1632fcd35826047dec6c5ad979c017e3638e1d1 /activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
parentcac3be6341f95c9a347d62173a4a130d1e42141b (diff)
downloadrails-3dce96a6b1242452860e3a9560ccfb357cede0b1.tar.gz
rails-3dce96a6b1242452860e3a9560ccfb357cede0b1.tar.bz2
rails-3dce96a6b1242452860e3a9560ccfb357cede0b1.zip
Refactor column initialization into `new_column_from_field`
that accepts results of SHOW FIELDS
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb32
1 files changed, 17 insertions, 15 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 69f797da3a..9e7487b27f 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -221,21 +221,23 @@ module ActiveRecord
end.compact
end
- # Returns the list of all column definitions for a table.
- def columns(table_name) # :nodoc:
- table_name = table_name.to_s
- column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod, collation, comment|
- oid = oid.to_i
- fmod = fmod.to_i
- type_metadata = fetch_type_metadata(column_name, type, oid, fmod)
- default_value = extract_value_from_default(default)
- default_function = extract_default_function(default_value, default)
- new_column(column_name, default_value, type_metadata, !notnull, table_name, default_function, collation, comment: comment.presence)
- end
- end
-
- def new_column(*args) # :nodoc:
- PostgreSQLColumn.new(*args)
+ def new_column_from_field(table_name, field) # :nondoc:
+ column_name, type, default, notnull, oid, fmod, collation, comment = field
+ oid = oid.to_i
+ fmod = fmod.to_i
+ type_metadata = fetch_type_metadata(column_name, type, oid, fmod)
+ default_value = extract_value_from_default(default)
+ default_function = extract_default_function(default_value, default)
+ PostgreSQLColumn.new(
+ column_name,
+ default_value,
+ type_metadata,
+ !notnull,
+ table_name,
+ default_function,
+ collation,
+ comment: comment.presence
+ )
end
def table_options(table_name) # :nodoc: