Permalink
Browse files

clear schema_migrations in Schema.define

  • Loading branch information...
1 parent 7139aa8 commit b07c2c0fd3130bb69cf8d846e46762a7c3972107 @joshsusser joshsusser committed Mar 21, 2010
@@ -46,10 +46,12 @@ def migrations_path
# ...
# 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
@@ -35,12 +35,9 @@ def dump(stream)
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 @@ def header(stream)
#
# 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 @@ def trailer(stream)
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)
@@ -60,6 +60,17 @@ def test_migration_adds_row_to_migrations_table
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

0 comments on commit b07c2c0

Please sign in to comment.