diff options
author | Jamis Buck <jamis@37signals.com> | 2005-07-30 10:16:21 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-07-30 10:16:21 +0000 |
commit | da874a4af817ebeb9421934b2a4e4e0032b1234d (patch) | |
tree | 29b3e248526352bb6697298e876579a8ee374cb5 /activerecord/lib/active_record/connection_adapters | |
parent | 0ea1375d7526cd1bbd74947f292d13b83a7617e6 (diff) | |
download | rails-da874a4af817ebeb9421934b2a4e4e0032b1234d.tar.gz rails-da874a4af817ebeb9421934b2a4e4e0032b1234d.tar.bz2 rails-da874a4af817ebeb9421934b2a4e4e0032b1234d.zip |
Allow add_column and create_table to specify NOT NULL #1712 [emptysands@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1955 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 18 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 2 |
2 files changed, 13 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 532d582565..f5aa09c1f2 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -437,6 +437,11 @@ module ActiveRecord column_type_sql << "(#{limit})" if limit column_type_sql end + + def add_column_options!(sql, options) + sql << " NOT NULL" if options[:null] == false + sql << " DEFAULT '#{options[:default]}'" unless options[:default].nil? + end protected def log(sql, name) @@ -488,16 +493,12 @@ module ActiveRecord "%s %s" % [message, dump] end end - - def add_column_options!(sql, options) - sql << " DEFAULT '#{options[:default]}'" unless options[:default].nil? - end end - class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :default) + class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :default, :null) def to_sql column_sql = "#{name} #{type_to_sql(type.to_sym, limit)}" - column_sql << " DEFAULT '#{default}'" if default + add_column_options!(column_sql, :null => null, :default => default) column_sql end alias to_s :to_sql @@ -506,6 +507,10 @@ module ActiveRecord def type_to_sql(name, limit) base.type_to_sql(name, limit) rescue name end + + def add_column_options!(sql, options) + base.add_column_options!(sql, options) + end end class TableDefinition @@ -528,6 +533,7 @@ module ActiveRecord column = self[name] || ColumnDefinition.new(@base, name, type) column.limit = options[:limit] || native[type.to_sym][:limit] if options[:limit] or native[type.to_sym] column.default = options[:default] + column.null = options[:null] @columns << column unless @columns.include? column self end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 5e3ef53c82..af2de4f706 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -239,7 +239,7 @@ module ActiveRecord transaction do move_table(table_name, altered_table_name, - options.merge(:temporary => true), &caller) + options.merge(:temporary => true)) move_table(altered_table_name, table_name, &caller) end end |