aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-06-03 21:41:40 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-06-03 21:41:40 +0000
commit7f00f51239f112ef6c70293665bcf0a5e2c313db (patch)
treef04b9440378e3fd5dbaad82511562c25a65aa5ad /activerecord
parent3e67e0b3b2c192335daeede83430dc6e5042fec3 (diff)
downloadrails-7f00f51239f112ef6c70293665bcf0a5e2c313db.tar.gz
rails-7f00f51239f112ef6c70293665bcf0a5e2c313db.tar.bz2
rails-7f00f51239f112ef6c70293665bcf0a5e2c313db.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb5
-rw-r--r--activerecord/test/migration_test.rb3
3 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 698bf850e9..b2f4afd24f 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -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]
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index cf4114aacc..7b7232ea13 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -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
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index 0f837841e1..88a94d8710 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -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)"