Class: DohDb::MigrateChecker
Instance Method Summary collapse
-
#initialize(database = nil) ⇒ MigrateChecker
constructor
A new instance of MigrateChecker.
- #run ⇒ Object
Constructor Details
#initialize(database = nil) ⇒ MigrateChecker
Returns a new instance of MigrateChecker.
9 10 11 12 13 14 15 16 17 |
# File 'lib/doh/mysql/migrate_check.rb', line 9 def initialize(database = nil) @database = database || DohApp::config['primary_database'] @data_directory = File.join(DohApp::home, 'database', @database) @check_database = 'migration_check_database' @sql_previous = "/tmp/check_migration_#{@database}_previous.sql" @sql_previous_up = "/tmp/check_migration_#{@database}_previous_up.sql" @sql_latest = "/tmp/check_migration_#{@database}_latest.sql" @sql_latest_down = "/tmp/check_migration_#{@database}_latest_down.sql" end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/doh/mysql/migrate_check.rb', line 19 def run svnout = `svn st #@data_directory` unless svnout.strip.empty? return [false, "svn status shows local changes in #@data_directory -- this needs to be resolved before migration can be checked"] end @latest_version = DohDb::latest_database_version(@database) if @latest_version == 0 return [true, "no migrations to check, database version is still at 0"] end @previous_version, @previous_svn_revision = DohDb::locked_version_info(@database) if @latest_version == @previous_version return [true, "no unlocked migration exists, nothing to check"] end dbmigrator = DohDb::DatabaseMigrator.new(@check_database, @database) if File.exist?(dbmigrator.up_filename(@latest_version + 1)) puts "multiple unlocked versions exist, should merge into version: #{@latest_version}" exit 1 end dohlog.debug("comparing database revisions #@previous_version and #@latest_version") dohlog.debug("svn updating to revision #@previous_svn_revision, building database, dumping as #{@sql_previous}") execute_cmd("svn up -r#@previous_svn_revision #@data_directory") DohDb::DatabaseCreator.new.exclude_scripts.create_database_copy(@check_database, @database, true) dump_sql(@sql_previous) dohlog.debug("svn updating to current revision, migrating to latest database version, dumping as #{@sql_previous_up}") execute_cmd("svn up #@data_directory") dbmigrator.update dump_sql(@sql_previous_up) dohlog.debug("re-creating database from current database files, dumping as #{@sql_latest}") begin DohDb::DatabaseCreator.new.exclude_scripts.create_database_copy(@check_database, @database, true) rescue Errno::ENOENT => e puts 'got exception during database creation -- possible view in order.yml that doesn\'t exist?' raise e end dump_sql(@sql_latest) dohlog.debug("migrating to previous version, dumping as #{@sql_latest_down}") DohDb::DatabaseMigrator.new(@check_database, @database).make_version(@previous_version) dump_sql(@sql_latest_down) diffstr = diff(@sql_previous, @sql_latest_down) return [false, diffstr] unless diffstr.empty? diffstr = diff(@sql_previous_up, @sql_latest) return [false, diffstr] unless diffstr.empty? File.delete(@sql_previous) File.delete(@sql_previous_up) File.delete(@sql_latest) File.delete(@sql_latest_down) [true, 'unlocked migration compared successfully'] end |