lib/migration.rb in dm-migrations-0.9.2 vs lib/migration.rb in dm-migrations-0.9.3

- old
+ new

@@ -1,7 +1,7 @@ require 'rubygems' -gem 'dm-core', '=0.9.2' +gem 'dm-core', '=0.9.3' require 'dm-core' require 'benchmark' require File.dirname(__FILE__) + '/sql' module DataMapper @@ -49,34 +49,34 @@ @down_action = block end # perform the migration by running the code in the #up block def perform_up - res = nil + result = nil if needs_up? # DataMapper.database.adapter.transaction do say_with_time "== Performing Up Migration ##{position}: #{name}", 0 do - res = @up_action.call + result = @up_action.call end update_migration_info(:up) # end end - res + result end # un-do the migration by running the code in the #down block def perform_down - res = nil + result = nil if needs_down? # DataMapper.database.adapter.transaction do say_with_time "== Performing Down Migration ##{position}: #{name}", 0 do - res = @down_action.call + result = @down_action.call end update_migration_info(:down) # end end - res + result end # execute raw SQL def execute(sql) say_with_time(sql) do @@ -125,12 +125,10 @@ # output the given text, but only if verbose mode is on def write(text="") puts text if @verbose end - protected - # Inserts or removes a row into the `migration_info` table, so we can mark this migration as run, or un-done def update_migration_info(direction) save, @verbose = @verbose, false create_migration_info_table_if_needed @@ -142,11 +140,11 @@ end @verbose = save end def create_migration_info_table_if_needed - save, @verbose = @verbose, true # false + save, @verbose = @verbose, false unless migration_info_table_exists? execute("CREATE TABLE #{migration_info_table} (#{migration_name_column} VARCHAR(255) UNIQUE)") end @verbose = save end @@ -166,16 +164,16 @@ @adapter.query("SELECT #{migration_name_column} FROM #{migration_info_table} WHERE #{migration_name_column} = #{quoted_name}") end # True if the migration needs to be run def needs_up? - create_migration_info_table_if_needed + return true unless migration_info_table_exists? migration_record.empty? end # True if the migration has already been run def needs_down? - create_migration_info_table_if_needed + return false unless migration_info_table_exists? ! migration_record.empty? end # Quoted table name, for the adapter def migration_info_table