aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-03 11:44:11 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-03 12:00:09 -0800
commit47737681fdfe4986dc7426b174f81d2b8daca991 (patch)
treeb7dfb614ca77c5c702c030af20fa7ae91cb8a0dc /activerecord
parent226ea0e9e817a2e449d989d925c36cf6a4cfd67b (diff)
downloadrails-47737681fdfe4986dc7426b174f81d2b8daca991.tar.gz
rails-47737681fdfe4986dc7426b174f81d2b8daca991.tar.bz2
rails-47737681fdfe4986dc7426b174f81d2b8daca991.zip
in the middle of refactoring
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/migration.rb4
-rw-r--r--activerecord/test/cases/migration_test.rb80
-rw-r--r--activerecord/test/migrations/interleaved/pass_1/3_interleaved_innocent_jointable.rb (renamed from activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb)4
-rw-r--r--activerecord/test/migrations/interleaved/pass_2/1_interleaved_people_have_last_names.rb (renamed from activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb)4
-rw-r--r--activerecord/test/migrations/interleaved/pass_2/3_interleaved_innocent_jointable.rb (renamed from activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb)4
-rw-r--r--activerecord/test/migrations/interleaved/pass_3/1_interleaved_people_have_last_names.rb (renamed from activerecord/test/migrations/valid/1_people_have_last_names.rb)4
-rw-r--r--activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb8
-rw-r--r--activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb8
-rw-r--r--activerecord/test/migrations/interleaved/pass_3/3_interleaved_innocent_jointable.rb (renamed from activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb)4
-rw-r--r--activerecord/test/migrations/valid/1_valid_people_have_last_names.rb (renamed from activerecord/test/migrations/valid_with_timestamps/20100101010101_people_have_last_names.rb)4
-rw-r--r--activerecord/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb (renamed from activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb)4
-rw-r--r--activerecord/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb (renamed from activerecord/test/migrations/valid_with_timestamps/20100201010101_we_need_reminders.rb)4
-rw-r--r--activerecord/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb (renamed from activerecord/test/migrations/valid_with_timestamps/20100301010101_innocent_jointable.rb)4
13 files changed, 60 insertions, 76 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index d80416149e..4dc67a0905 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -518,6 +518,7 @@ module ActiveRecord
when target_version.nil?
up(migrations_path, target_version)
when current_version == 0 && target_version == 0
+ []
when current_version > target_version
down(migrations_path, target_version)
else
@@ -647,6 +648,7 @@ module ActiveRecord
# skip the last migration if we're headed down, but not ALL the way down
runnable.pop if down? && target
+ ran = []
runnable.each do |migration|
Base.logger.info "Migrating to #{migration.name} (#{migration.version})" if Base.logger
@@ -666,11 +668,13 @@ module ActiveRecord
migration.migrate(@direction)
record_version_state_after_migrating(migration.version)
end
+ ran << migration
rescue => e
canceled_msg = Base.connection.supports_ddl_transactions? ? "this and " : ""
raise StandardError, "An error has occurred, #{canceled_msg}all later migrations canceled:\n\n#{e}", e.backtrace
end
end
+ ran
end
def migrations
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index 3037d73a1b..d7ff3e68d9 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -5,10 +5,8 @@ require 'models/person'
require 'models/topic'
require 'models/developer'
-require MIGRATIONS_ROOT + "/valid/1_people_have_last_names"
require MIGRATIONS_ROOT + "/valid/2_we_need_reminders"
require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers"
-require MIGRATIONS_ROOT + "/interleaved/pass_3/2_i_raise_on_down"
if ActiveRecord::Base.connection.supports_migrations?
class BigNumber < ActiveRecord::Base; end
@@ -21,8 +19,8 @@ if ActiveRecord::Base.connection.supports_migrations?
end
def puts(text="")
- self.class.message_count ||= 0
- self.class.message_count += 1
+ ActiveRecord::Migration.message_count ||= 0
+ ActiveRecord::Migration.message_count += 1
end
end
@@ -52,7 +50,7 @@ if ActiveRecord::Base.connection.supports_migrations?
def setup
ActiveRecord::Migration.verbose = true
- PeopleHaveLastNames.message_count = 0
+ ActiveRecord::Migration.message_count = 0
end
def teardown
@@ -1271,7 +1269,7 @@ if ActiveRecord::Base.connection.supports_migrations?
def test_finds_migrations
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
- [[1, 'PeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i|
+ [[1, 'ValidPeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i|
assert_equal migrations[i].version, pair.first
assert_equal migrations[i].name, pair.last
end
@@ -1283,39 +1281,30 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_equal 1, migrations.size
assert_equal migrations[0].version, 3
- assert_equal migrations[0].name, 'InnocentJointable'
+ assert_equal migrations[0].name, 'InterleavedInnocentJointable'
end
def test_relative_migrations
- $".delete_if do |fname|
- fname == (MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb")
- end
- Object.send(:remove_const, :PeopleHaveLastNames)
-
- Dir.chdir(MIGRATIONS_ROOT) do
+ list = Dir.chdir(MIGRATIONS_ROOT) do
ActiveRecord::Migrator.up("valid/", 1)
end
- assert defined?(PeopleHaveLastNames)
+ migration_proxy = list.find { |item|
+ item.name == 'ValidPeopleHaveLastNames'
+ }
+ assert migration_proxy, 'should find pending migration'
end
def test_only_loads_pending_migrations
# migrate up to 1
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
- # now unload the migrations that have been defined
- Object.send(:remove_const, :PeopleHaveLastNames)
-
- ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", nil)
+ proxies = ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", nil)
- assert !defined? PeopleHaveLastNames
-
- %w(WeNeedReminders, InnocentJointable).each do |migration|
- assert defined? migration
- end
-
- ensure
- load(MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb")
+ names = proxies.map(&:name)
+ assert !names.include?('ValidPeopleHaveLastNames')
+ assert names.include?('WeNeedReminders')
+ assert names.include?('InnocentJointable')
end
def test_target_version_zero_should_run_only_once
@@ -1325,16 +1314,9 @@ if ActiveRecord::Base.connection.supports_migrations?
# migrate down to 0
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
- # now unload the migrations that have been defined
- PeopleHaveLastNames.unloadable
- ActiveSupport::Dependencies.remove_unloadable_constants!
-
# migrate down to 0 again
- ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
-
- assert !defined? PeopleHaveLastNames
- ensure
- load(MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb")
+ proxies = ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
+ assert_equal [], proxies
end
def test_migrator_db_has_no_schema_migrations_table
@@ -1351,20 +1333,20 @@ if ActiveRecord::Base.connection.supports_migrations?
def test_migrator_verbosity
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
- assert_operator PeopleHaveLastNames.message_count, :>, 0
- PeopleHaveLastNames.message_count = 0
+ assert_not_equal 0, ActiveRecord::Migration.message_count
+ ActiveRecord::Migration.message_count = 0
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
- assert_operator PeopleHaveLastNames.message_count, :>, 0
- PeopleHaveLastNames.message_count = 0
+ assert_not_equal 0, ActiveRecord::Migration.message_count
+ ActiveRecord::Migration.message_count = 0
end
def test_migrator_verbosity_off
- PeopleHaveLastNames.verbose = false
+ ActiveRecord::Migration.verbose = false
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
- assert_equal 0, PeopleHaveLastNames.message_count
+ assert_equal 0, ActiveRecord::Migration.message_count
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
- assert_equal 0, PeopleHaveLastNames.message_count
+ assert_equal 0, ActiveRecord::Migration.message_count
end
def test_migrator_going_down_due_to_version_target
@@ -1658,10 +1640,6 @@ if ActiveRecord::Base.connection.supports_migrations?
end # SexyMigrationsTest
class MigrationLoggerTest < ActiveRecord::TestCase
- def setup
- Object.send(:remove_const, :InnocentJointable)
- end
-
def test_migration_should_be_run_without_logger
previous_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
@@ -1675,7 +1653,7 @@ if ActiveRecord::Base.connection.supports_migrations?
class InterleavedMigrationsTest < ActiveRecord::TestCase
def setup
- Object.send(:remove_const, :PeopleHaveLastNames)
+ #Object.send(:remove_const, :PeopleHaveLastNames)
end
def test_migrator_interleaved_migrations
@@ -1688,10 +1666,12 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
- Object.send(:remove_const, :PeopleHaveLastNames)
- Object.send(:remove_const, :InnocentJointable)
assert_nothing_raised do
- ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/interleaved/pass_3")
+ proxies = ActiveRecord::Migrator.down(
+ MIGRATIONS_ROOT + "/interleaved/pass_3")
+ names = proxies.map(&:name)
+ assert names.include?('InterleavedPeopleHaveLastNames')
+ assert names.include?('InterleavedInnocentJointable')
end
end
end
diff --git a/activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_1/3_interleaved_innocent_jointable.rb
index 21c9ca5328..bf912fbfc8 100644
--- a/activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb
+++ b/activerecord/test/migrations/interleaved/pass_1/3_interleaved_innocent_jointable.rb
@@ -1,4 +1,4 @@
-class InnocentJointable < ActiveRecord::Migration
+class InterleavedInnocentJointable < ActiveRecord::Migration
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
@@ -9,4 +9,4 @@ class InnocentJointable < ActiveRecord::Migration
def self.down
drop_table "people_reminders"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb b/activerecord/test/migrations/interleaved/pass_2/1_interleaved_people_have_last_names.rb
index 81af5fef5e..c6c94213a0 100644
--- a/activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb
+++ b/activerecord/test/migrations/interleaved/pass_2/1_interleaved_people_have_last_names.rb
@@ -1,4 +1,4 @@
-class PeopleHaveLastNames < ActiveRecord::Migration
+class InterleavedPeopleHaveLastNames < ActiveRecord::Migration
def self.up
add_column "people", "last_name", :string
end
@@ -6,4 +6,4 @@ class PeopleHaveLastNames < ActiveRecord::Migration
def self.down
remove_column "people", "last_name"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_2/3_interleaved_innocent_jointable.rb
index 21c9ca5328..bf912fbfc8 100644
--- a/activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb
+++ b/activerecord/test/migrations/interleaved/pass_2/3_interleaved_innocent_jointable.rb
@@ -1,4 +1,4 @@
-class InnocentJointable < ActiveRecord::Migration
+class InterleavedInnocentJointable < ActiveRecord::Migration
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
@@ -9,4 +9,4 @@ class InnocentJointable < ActiveRecord::Migration
def self.down
drop_table "people_reminders"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/valid/1_people_have_last_names.rb b/activerecord/test/migrations/interleaved/pass_3/1_interleaved_people_have_last_names.rb
index 81af5fef5e..c6c94213a0 100644
--- a/activerecord/test/migrations/valid/1_people_have_last_names.rb
+++ b/activerecord/test/migrations/interleaved/pass_3/1_interleaved_people_have_last_names.rb
@@ -1,4 +1,4 @@
-class PeopleHaveLastNames < ActiveRecord::Migration
+class InterleavedPeopleHaveLastNames < ActiveRecord::Migration
def self.up
add_column "people", "last_name", :string
end
@@ -6,4 +6,4 @@ class PeopleHaveLastNames < ActiveRecord::Migration
def self.down
remove_column "people", "last_name"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb b/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb
deleted file mode 100644
index 9b1ce9f017..0000000000
--- a/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class IRaiseOnDown < ActiveRecord::Migration
- def self.up
- end
-
- def self.down
- raise
- end
-end \ No newline at end of file
diff --git a/activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb b/activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb
new file mode 100644
index 0000000000..6849995f5e
--- /dev/null
+++ b/activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb
@@ -0,0 +1,8 @@
+class InterleavedIRaiseOnDown < ActiveRecord::Migration
+ def self.up
+ end
+
+ def self.down
+ raise
+ end
+end
diff --git a/activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_3/3_interleaved_innocent_jointable.rb
index 21c9ca5328..bf912fbfc8 100644
--- a/activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb
+++ b/activerecord/test/migrations/interleaved/pass_3/3_interleaved_innocent_jointable.rb
@@ -1,4 +1,4 @@
-class InnocentJointable < ActiveRecord::Migration
+class InterleavedInnocentJointable < ActiveRecord::Migration
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
@@ -9,4 +9,4 @@ class InnocentJointable < ActiveRecord::Migration
def self.down
drop_table "people_reminders"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/valid_with_timestamps/20100101010101_people_have_last_names.rb b/activerecord/test/migrations/valid/1_valid_people_have_last_names.rb
index 81af5fef5e..06cb911117 100644
--- a/activerecord/test/migrations/valid_with_timestamps/20100101010101_people_have_last_names.rb
+++ b/activerecord/test/migrations/valid/1_valid_people_have_last_names.rb
@@ -1,4 +1,4 @@
-class PeopleHaveLastNames < ActiveRecord::Migration
+class ValidPeopleHaveLastNames < ActiveRecord::Migration
def self.up
add_column "people", "last_name", :string
end
@@ -6,4 +6,4 @@ class PeopleHaveLastNames < ActiveRecord::Migration
def self.down
remove_column "people", "last_name"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb b/activerecord/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb
index 81af5fef5e..1da99ceaba 100644
--- a/activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb
+++ b/activerecord/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb
@@ -1,4 +1,4 @@
-class PeopleHaveLastNames < ActiveRecord::Migration
+class ValidWithTimestampsPeopleHaveLastNames < ActiveRecord::Migration
def self.up
add_column "people", "last_name", :string
end
@@ -6,4 +6,4 @@ class PeopleHaveLastNames < ActiveRecord::Migration
def self.down
remove_column "people", "last_name"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/valid_with_timestamps/20100201010101_we_need_reminders.rb b/activerecord/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb
index d5e71ce8ef..cb6d735c8b 100644
--- a/activerecord/test/migrations/valid_with_timestamps/20100201010101_we_need_reminders.rb
+++ b/activerecord/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb
@@ -1,4 +1,4 @@
-class WeNeedReminders < ActiveRecord::Migration
+class ValidWithTimestampsWeNeedReminders < ActiveRecord::Migration
def self.up
create_table("reminders") do |t|
t.column :content, :text
@@ -9,4 +9,4 @@ class WeNeedReminders < ActiveRecord::Migration
def self.down
drop_table "reminders"
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/migrations/valid_with_timestamps/20100301010101_innocent_jointable.rb b/activerecord/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb
index 21c9ca5328..4bd4b4714d 100644
--- a/activerecord/test/migrations/valid_with_timestamps/20100301010101_innocent_jointable.rb
+++ b/activerecord/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb
@@ -1,4 +1,4 @@
-class InnocentJointable < ActiveRecord::Migration
+class ValidWithTimestampsInnocentJointable < ActiveRecord::Migration
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
@@ -9,4 +9,4 @@ class InnocentJointable < ActiveRecord::Migration
def self.down
drop_table "people_reminders"
end
-end \ No newline at end of file
+end