Permalink
Browse files

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
  • Loading branch information...
1 parent 3e67e0b commit 7f00f51239f112ef6c70293665bcf0a5e2c313db @dhh dhh committed Jun 3, 2006
View
@@ -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 @@ def copy_table_indexes(from, to) #:nodoc:
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 @@ def test_add_column_not_null_with_default
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)"

0 comments on commit 7f00f51

Please sign in to comment.