Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

record migration timestamp when migrations run

  • Loading branch information...
commit 4e4e9ad48a222ac94a904c62ae684c609bd8e177 1 parent c283cdd
Josh Susser joshsusser authored
17 activerecord/lib/active_record/migration.rb
View
@@ -628,7 +628,7 @@ def run
raise UnknownMigrationVersionError.new(@target_version) if target.nil?
unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i))
target.migrate(@direction)
- record_version_state_after_migrating(target.version)
+ record_version_state_after_migrating(target)
end
end
@@ -664,7 +664,7 @@ def migrate
begin
ddl_transaction do
migration.migrate(@direction)
- record_version_state_after_migrating(migration.version)
+ record_version_state_after_migrating(migration)
end
rescue => e
canceled_msg = Base.connection.supports_ddl_transactions? ? "this and " : ""
@@ -690,16 +690,19 @@ def migrated
end
private
- def record_version_state_after_migrating(version)
+ def record_version_state_after_migrating(target)
table = Arel::Table.new(self.class.schema_migrations_table_name)
@migrated_versions ||= []
if down?
- @migrated_versions.delete(version)
- table.where(table["version"].eq(version.to_s)).delete
+ @migrated_versions.delete(target.version)
+ table.where(table["version"].eq(target.version.to_s)).delete
else
- @migrated_versions.push(version).sort!
- table.insert table["version"] => version.to_s
+ @migrated_versions.push(target.version).sort!
+ table.insert(
+ table["version"] => target.version.to_s,
+ table["migrated_at"] => Time.now
+ )
end
end
49 activerecord/test/cases/migration_test.rb
View
@@ -445,6 +445,43 @@ def test_create_table_without_a_block
Person.connection.drop_table table_name rescue nil
end
+ def test_create_table_with_custom_sequence_name
+ return unless current_adapter? :OracleAdapter
+
+ # table name is 29 chars, the standard sequence name will
+ # be 33 chars and fail
+ assert_raise(ActiveRecord::StatementInvalid) do
+ begin
+ Person.connection.create_table :table_with_name_thats_just_ok do |t|
+ t.column :foo, :string, :null => false
+ end
+ ensure
+ Person.connection.drop_table :table_with_name_thats_just_ok rescue nil
+ end
+ end
+
+ # should be all good w/ a custom sequence name
+ assert_nothing_raised do
+ begin
+ Person.connection.create_table :table_with_name_thats_just_ok,
+ :sequence_name => 'suitably_short_seq' do |t|
+ t.column :foo, :string, :null => false
+ end
+
+ Person.connection.execute("select suitably_short_seq.nextval from dual")
+
+ ensure
+ Person.connection.drop_table :table_with_name_thats_just_ok,
+ :sequence_name => 'suitably_short_seq' rescue nil
+ end
+ end
+
+ # confirm the custom sequence got dropped
+ assert_raise(ActiveRecord::StatementInvalid) do
+ Person.connection.execute("select suitably_short_seq.nextval from dual")
+ end
+ end
+
# Sybase, and SQLite3 will not allow you to add a NOT NULL
# column to a table without a default value.
unless current_adapter?(:SybaseAdapter, :SQLite3Adapter)
@@ -1462,6 +1499,17 @@ def test_schema_migrations_table_name
ActiveRecord::Base.table_name_suffix = ""
end
+ def test_migration_row_includes_timestamp
+ conn = ActiveRecord::Base.connection
+ sm_table = ActiveRecord::Migrator.schema_migrations_table_name
+
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
+
+ conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}").each do |row|
+ assert_match /^2\d\d\d-/, row["migrated_at"], "missing migrated_at"
+ end
+ end
+
def test_proper_table_name
assert_equal "table", ActiveRecord::Migrator.proper_table_name('table')
assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table)
@@ -2117,4 +2165,3 @@ def test_copying_migrations_to_empty_directory
end
end
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.