From 8f358f397f11a87c649f76644690461f0017cbff Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 26 Jun 2010 20:12:23 -0300 Subject: Refactor of column_exists? method and this works with PostgreSQL --- .../connection_adapters/abstract/schema_statements.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb') 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 -- cgit v1.2.3