From 0639e1ca7c63afa79b54cc1eb73871026f9b473d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 6 Oct 2005 03:20:28 +0000 Subject: Added :force option to create_table that'll try to drop the table if it already exists before creating git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2473 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ .../active_record/connection_adapters/abstract/schema_statements.rb | 5 +++++ activerecord/lib/active_record/schema_dumper.rb | 1 + 3 files changed, 8 insertions(+) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index a98479bbd2..3479cc9d81 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added :force option to create_table that'll try to drop the table if it already exists before creating + * Fix transactions so that calling return while inside a transaction will not leave an open transaction on the connection. [Nicholas Seckar] * Use foreign_key inflection uniformly. #2156 [Blair Zajac ] 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 ea9173039c..861480d980 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -79,6 +79,11 @@ module ActiveRecord table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false yield table_definition + + if options[:force] + drop_table(name) rescue nil + end + create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE " create_sql << "#{name} (" create_sql << table_definition.to_sql diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 30d6f6927b..f4ce67e9aa 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -53,6 +53,7 @@ HEADER stream.print " create_table #{table.inspect}" stream.print ", :id => false" if !columns.detect { |c| c.name == "id" } + stream.print ", :force => true" stream.puts " do |t|" columns.each do |column| -- cgit v1.2.3