aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2010-03-20 19:46:17 -0700
committerJosh Susser <josh@hasmanythrough.com>2010-12-01 11:01:15 -0800
commitb07c2c0fd3130bb69cf8d846e46762a7c3972107 (patch)
tree15d8dd984efc7d986d98641bf6a73973c2405ea9 /activerecord
parent7139aa878ceea8dd17a60955cd4d07f5f68980d9 (diff)
downloadrails-b07c2c0fd3130bb69cf8d846e46762a7c3972107.tar.gz
rails-b07c2c0fd3130bb69cf8d846e46762a7c3972107.tar.bz2
rails-b07c2c0fd3130bb69cf8d846e46762a7c3972107.zip
clear schema_migrations in Schema.define
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/schema.rb4
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb8
-rw-r--r--activerecord/test/cases/ar_schema_test.rb11
3 files changed, 17 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb
index c9b5539e4f..4b846f2e27 100644
--- a/activerecord/lib/active_record/schema.rb
+++ b/activerecord/lib/active_record/schema.rb
@@ -46,10 +46,12 @@ module ActiveRecord
# ...
# end
def self.define(info={}, &block)
+ Base.connection.drop_table(ActiveRecord::Migrator.schema_migrations_table_name)
+ initialize_schema_migrations_table
+
schema = new
schema.instance_eval(&block)
- initialize_schema_migrations_table
assume_migrated_upto_version(info[:version], schema.migrations_path) unless info[:version].blank?
end
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index a53dce0cf4..794a354917 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -35,12 +35,9 @@ module ActiveRecord
def initialize(connection)
@connection = connection
@types = @connection.native_database_types
- @version = Migrator::current_version rescue nil
end
def header(stream)
- define_params = @version ? ":version => #{@version}" : ""
-
stream.puts <<HEADER
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
@@ -54,7 +51,7 @@ module ActiveRecord
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(#{define_params}) do
+ActiveRecord::Schema.define do
HEADER
end
@@ -66,10 +63,11 @@ HEADER
def migrations(stream)
rows = @connection.select_all("SELECT * FROM #{@connection.quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)}")
rows.each do |migration|
- line = %Q(migration "#{migration['version']}")
+ line = %Q( migration "#{migration['version']}")
line << %Q(, "#{migration['name']}") unless migration['name'].blank?
stream.puts line
end
+ stream.puts ""
end
def tables(stream)
diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb
index e7f3907ff5..930a57330d 100644
--- a/activerecord/test/cases/ar_schema_test.rb
+++ b/activerecord/test/cases/ar_schema_test.rb
@@ -60,6 +60,17 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_equal "add_magic_power_to_unicorns", rows[1]["name"]
assert_match /^2\d\d\d-/, rows[1]["migrated_at"]
end
+
+ def test_define_clears_schema_migrations
+ assert_nothing_raised do
+ ActiveRecord::Schema.define do
+ migration("123001")
+ end
+ ActiveRecord::Schema.define do
+ migration("123001")
+ end
+ end
+ end
end
end