From 3ec212e3c9c815e9993cbea409c60774ea75cd30 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 1 Dec 2010 17:08:01 -0800 Subject: [PATCH] rolling out migrated_at until I can fix the build --- activerecord/CHANGELOG | 4 -- .../abstract/schema_statements.rb | 18 ++----- activerecord/lib/active_record/migration.rb | 18 +++---- activerecord/lib/active_record/schema.rb | 19 ++----- .../lib/active_record/schema_dumper.rb | 16 ++---- activerecord/test/cases/ar_schema_test.rb | 35 ------------- activerecord/test/cases/migration_test.rb | 52 +++---------------- activerecord/test/cases/schema_dumper_test.rb | 19 ------- 8 files changed, 25 insertions(+), 156 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e6c6883fc7..f46db909ba 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,9 +1,5 @@ *Rails 3.1.0 (unreleased)* -* The `schema_migrations` table now contains a column `name` which stores the -name of the migration that was executed, and `migrated_at` which stores the date -when the migration was executed. (Thanks Josh Susser!) - * ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. 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 de7d358df9..4e770c37da 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -422,21 +422,9 @@ module ActiveRecord def initialize_schema_migrations_table sm_table = ActiveRecord::Migrator.schema_migrations_table_name - if table_exists?(sm_table) - cols = columns(sm_table).collect { |col| col.name } - unless cols.include?("migrated_at") - add_column sm_table, :migrated_at, :datetime - update "UPDATE #{quote_table_name(sm_table)} SET migrated_at = '#{quoted_date(Time.now)}' WHERE migrated_at IS NULL" - change_column sm_table, :migrated_at, :datetime, :null => false - end - unless cols.include?("name") - add_column sm_table, :name, :string, :null => false, :default => "" - end - else + unless table_exists?(sm_table) create_table(sm_table, :id => false) do |schema_migrations_table| schema_migrations_table.column :version, :string, :null => false - schema_migrations_table.column :name, :string, :null => false, :default => "" - schema_migrations_table.column :migrated_at, :datetime, :null => false end add_index sm_table, :version, :unique => true, :name => "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}" @@ -464,7 +452,7 @@ module ActiveRecord end unless migrated.include?(version) - execute "INSERT INTO #{sm_table} (version,migrated_at) VALUES ('#{version}','#{Time.now.to_s(:db)}')" + execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')" end inserted = Set.new @@ -472,7 +460,7 @@ module ActiveRecord if inserted.include?(v) raise "Duplicate migration #{v}. Please renumber your migrations to resolve the conflict." elsif v < version - execute "INSERT INTO #{sm_table} (version,migrated_at) VALUES ('#{v}','#{Time.now.to_s(:db)}')" + execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')" inserted << v end end diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index d2ebf656cb..f6321f1499 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -628,7 +628,7 @@ module ActiveRecord 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) + record_version_state_after_migrating(target.version) end end @@ -664,7 +664,7 @@ module ActiveRecord begin ddl_transaction do migration.migrate(@direction) - record_version_state_after_migrating(migration) + record_version_state_after_migrating(migration.version) end rescue => e canceled_msg = Base.connection.supports_ddl_transactions? ? "this and " : "" @@ -690,20 +690,16 @@ module ActiveRecord end private - def record_version_state_after_migrating(target) + def record_version_state_after_migrating(version) table = Arel::Table.new(self.class.schema_migrations_table_name) @migrated_versions ||= [] if down? - @migrated_versions.delete(target.version) - table.where(table["version"].eq(target.version.to_s)).delete + @migrated_versions.delete(version) + table.where(table["version"].eq(version.to_s)).delete else - @migrated_versions.push(target.version).sort! - table.insert( - table["version"] => target.version.to_s, - table["name"] => File.basename(target.filename,'.rb').gsub(/^\d+_/,''), - table["migrated_at"] => Time.now - ) + @migrated_versions.push(version).sort! + table.insert table["version"] => version.to_s end end diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb index 9a47fd3b84..c6bb5c1961 100644 --- a/activerecord/lib/active_record/schema.rb +++ b/activerecord/lib/active_record/schema.rb @@ -46,24 +46,13 @@ 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) - assume_migrated_upto_version(info[:version], schema.migrations_path) unless info[:version].blank? - end - - def migration(version, name="", options={}) - name, options = "", name if name.is_a?(Hash) - - table = Arel::Table.new(ActiveRecord::Migrator.schema_migrations_table_name) - table.insert( - table["version"] => version, - table["name"] => name, - table["migrated_at"] => Time.now - ) + unless info[:version].blank? + initialize_schema_migrations_table + assume_migrated_upto_version(info[:version], schema.migrations_path) + end end end end diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 794a354917..e30b481fe1 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -24,7 +24,6 @@ module ActiveRecord def dump(stream) header(stream) - migrations(stream) tables(stream) trailer(stream) stream @@ -35,9 +34,12 @@ 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 <
false) do |schema_migrations_table| - schema_migrations_table.column :version, :string, :null => false - end - @conn.insert "INSERT INTO #{@conn.quote_table_name(sm_table)} (version) VALUES (100)" - @conn.insert "INSERT INTO #{@conn.quote_table_name(sm_table)} (version) VALUES (200)" - - @conn.initialize_schema_migrations_table - - rows = @conn.select_all("SELECT * FROM #{@conn.quote_table_name(sm_table)}") - assert rows[0].has_key?("name") - assert rows[0].has_key?("migrated_at") - end end class MigrationTest < ActiveRecord::TestCase @@ -1462,21 +1438,6 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Base.table_name_suffix = "" end - def test_migration_row_includes_name_and_timestamp - conn = ActiveRecord::Base.connection - sm_table = ActiveRecord::Migrator.schema_migrations_table_name - - ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid") - - rows = conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}") - rows.each do |row| - assert_not_nil(row["migrated_at"], "missing migrated_at") - end - assert_equal "people_have_last_names", rows[0]["name"] - assert_equal "we_need_reminders", rows[1]["name"] - assert_equal "innocent_jointable", rows[2]["name"] - end - def test_proper_table_name assert_equal "table", ActiveRecord::Migrator.proper_table_name('table') assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table) @@ -2132,3 +2093,4 @@ if ActiveRecord::Base.connection.supports_migrations? end end end + diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 7914ee0a6f..9b2c7c00df 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -17,25 +17,6 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_no_match %r{create_table "schema_migrations"}, output end - def test_schema_dump_includes_migrations - $".delete_if do |fname| - fname == (MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb") - end - - conn = ActiveRecord::Base.connection - sm_table = ActiveRecord::Migrator.schema_migrations_table_name - conn.execute "DELETE FROM #{conn.quote_table_name(sm_table)}" - conn.remove_column "people", "last_name" rescue nil - conn.drop_table "reminders" rescue nil - conn.drop_table "people_reminders" rescue nil - ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid") - - output = standard_dump - assert_match %r{migration "1", "people_have_last_names"}, output - assert_match %r{migration "2", "we_need_reminders"}, output - assert_match %r{migration "3", "innocent_jointable"}, output - end - def test_schema_dump_excludes_sqlite_sequence output = standard_dump assert_no_match %r{create_table "sqlite_sequence"}, output