mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed migration trouble with SQLite when NOT NULL is used in the new definition (closes #5215) [greg@lapcominc.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4419 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
3e67e0b3b2
commit
7f00f51239
3 changed files with 7 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Fixed migration trouble with SQLite when NOT NULL is used in the new definition #5215 [greg@lapcominc.com]
|
||||
|
||||
* Fixed problems with eager loading and counting on SQL Server #5212 [kajism@yahoo.com]
|
||||
|
||||
* Fixed that count distinct should use the selected column even when using :include #5251 [anna@wota.jp]
|
||||
|
|
|
@ -316,9 +316,10 @@ module ActiveRecord
|
|||
def copy_table_contents(from, to, columns, rename = {}) #:nodoc:
|
||||
column_mappings = Hash[*columns.map {|name| [name, name]}.flatten]
|
||||
rename.inject(column_mappings) {|map, a| map[a.last] = a.first; map}
|
||||
|
||||
from_columns = columns(from).collect {|col| col.name}
|
||||
columns = columns.find_all{|col| from_columns.include?(column_mappings[col])}
|
||||
@connection.execute "SELECT * FROM #{from}" do |row|
|
||||
sql = "INSERT INTO #{to} VALUES ("
|
||||
sql = "INSERT INTO #{to} ("+columns*','+") VALUES ("
|
||||
sql << columns.map {|col| quote row[column_mappings[col]]} * ', '
|
||||
sql << ')'
|
||||
@connection.execute sql
|
||||
|
|
|
@ -173,7 +173,8 @@ if ActiveRecord::Base.connection.supports_migrations?
|
|||
Person.connection.create_table :testings do |t|
|
||||
t.column :foo, :string
|
||||
end
|
||||
Person.connection.add_column :testings, :bar, :string, :null => false, :default => "default"
|
||||
Person.connection.execute "insert into testings (foo) values ('hello')"
|
||||
assert_nothing_raised {Person.connection.add_column :testings, :bar, :string, :null => false, :default => "default" }
|
||||
|
||||
assert_raises(ActiveRecord::StatementInvalid) do
|
||||
Person.connection.execute "insert into testings (foo, bar) values ('hello', NULL)"
|
||||
|
|
Loading…
Reference in a new issue