aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-06-26 20:12:23 -0300
committerwycats <wycats@gmail.com>2010-06-26 17:09:46 -0700
commit8f358f397f11a87c649f76644690461f0017cbff (patch)
treec94a37b7e67521fee9a13fa88063762d2e9f1cbd /activerecord/lib
parent64fee27a554151eb87b2350c3834bbf8812520c8 (diff)
downloadrails-8f358f397f11a87c649f76644690461f0017cbff.tar.gz
rails-8f358f397f11a87c649f76644690461f0017cbff.tar.bz2
rails-8f358f397f11a87c649f76644690461f0017cbff.zip
Refactor of column_exists? method and this works with PostgreSQL
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb18
1 files changed, 6 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 5625dba45f..0216a8f4ac 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -63,18 +63,12 @@ module ActiveRecord
#
# # Check a column exists with a specific definition
# column_exists?(:suppliers, :name, :string, :limit => 100)
- def column_exists?(table_name, column_name, type = nil, options = nil)
- column_name = column_name.to_s
- if type
- if options
- sql_type = type_to_sql(type, options[:limit], options[:precision], options[:scale])
- columns(table_name).any?{ |c| c.name == column_name && c.sql_type == sql_type }
- else
- columns(table_name).any?{ |c| c.name == column_name && c.type == type }
- end
- else
- columns(table_name).any?{ |c| c.name == column_name }
- end
+ def column_exists?(table_name, column_name, type = nil, options = {})
+ columns(table_name).any?{ |c| c.name == column_name.to_s &&
+ (!type || c.type == type) &&
+ (!options[:limit] || c.limit == options[:limit]) &&
+ (!options[:precision] || c.precision == options[:precision]) &&
+ (!options[:scale] || c.scale == options[:scale]) }
end
# Creates a new table with the name +table_name+. +table_name+ may either