Class: DBMigrator

Inherits:
Object
  • Object
show all
Defined in:
common/db/db_migrator.rb

Constant Summary

MIGRATIONS_DIR =
File.join(File.dirname(__FILE__), "migrations")
PLUGIN_MIGRATIONS =
[]
PLUGIN_MIGRATION_DIRS =
{}

Class Method Summary (collapse)

Class Method Details

+ (Boolean) needs_updating?(db)

Returns:

  • (Boolean)


221
222
223
224
225
226
227
# File 'common/db/db_migrator.rb', line 221

def self.needs_updating?(db)
  $db_type = db.database_type
  return true unless Sequel::Migrator.is_current?(db, MIGRATIONS_DIR)
  PLUGIN_MIGRATIONS.each { |plugin| return true unless Sequel::Migrator.is_current?(db, PLUGIN_MIGRATIONS_DIR[plugin],
                                                                                    :table => "#{plugin}_schema_info") }
  return false
end

+ (Object) nuke_database(db)



214
215
216
217
218
219
# File 'common/db/db_migrator.rb', line 214

def self.nuke_database(db)
  $db_type = db.database_type
  PLUGIN_MIGRATIONS.reverse.each { |plugin| Sequel::Migrator.run(db, PLUGIN_MIGRATION_DIRS[plugin],
                                                                   :table => "#{plugin}_schema_info", :target => 0) }
  Sequel::Migrator.run(db, MIGRATIONS_DIR, :target => 0)
end

+ (Object) setup_database(db)



182
183
184
185
186
187
188
189
190
191
192
193
# File 'common/db/db_migrator.rb', line 182

def self.setup_database(db)
  begin 
    $db_type = db.database_type
    Sequel::Migrator.run(db, MIGRATIONS_DIR)
    PLUGIN_MIGRATIONS.each { |plugin| Sequel::Migrator.run(db, PLUGIN_MIGRATION_DIRS[plugin],
                                                           :table => "#{plugin}_schema_info") }
  rescue Exception => e
   $stderr.puts "     \n     \#{ 3.times { $stderr.puts \"!\" * 100  } } \n     \n     \n     Database migration error. \n     Your upgrade has encountered a problem. \n     You must resolve these issues before the database migration can complete.\n     \n     \n     Error: \n     \#{e.inspect}\n     \#{e.message}\n     \#{e.backtrace.join(\"\\n\")}\n\n     \n     \#{ 3.times { $stderr.puts \"!\" * 100  } }\n"
   
   raise e
  end
end