module Migration

Public Class Methods

run(schema_module, db, version=nil) click to toggle source
# File lib/jungle_path/migration/migration.rb, line 6
def self.run schema_module, db, version=nil
        Sequel.extension :migration

        db.base.loggers << Logger.new($stdout)
        db.base.identifier_input_method = :downcase
        version = schema_module.version unless version
        path = schema_module.migrations_path
        display_version = version || "'latest available'"

        puts "Migrating database to version: #{display_version} on #{db.config.host}.#{db.config.name}:#{db.config.port}."
        puts "Using migration files at: #{path}"

        if JunglePath::DBAccess::Meta::DB.exists? db.config # todo: fix for sql server!
                # migrate to current or passed version.
                if version
                        Sequel::Migrator.run(db.base, path, target: version)
                else
                        Sequel::Migrator.run(db.base, path)
                end
        else
                # create from scratch and set the version in the new db.
                puts "Database does not exist, run zcreatedb.rb and then zbootstrapdata.rb..."
                puts "Write some code to create the schema_info table with integer column version and set the version! This table should always have only one row."
        end
end