Class: Rack::App::SeQueL::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/app/sequel/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, migration_options) ⇒ Runner

Returns a new instance of Runner.



41
42
43
44
45
# File 'lib/rack/app/sequel/runner.rb', line 41

def initialize(options, migration_options)
  @code = 0
  @options = options
  @migration_options = migration_options
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



39
40
41
# File 'lib/rack/app/sequel/runner.rb', line 39

def code
  @code
end

Class Method Details

.setup_command(command) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rack/app/sequel/runner.rb', line 3

def self.setup_command(command)
  command.class_eval do

    option '-a', '--allow_missing_migration_files', 'In some cases, you may want to allow a migration in the database that does not exist in the filesystem' do
      migration_config[:allow_missing_migration_files] = true
    end

    option '-c', '--current [CURRENT_VERION]', 'Set the current version of the database for the execution' do |current_database_version|
      migration_config[:current] = current_database_version
    end

    # option '-r', '--relative [MIGRATION_COUNT]', 'Run the given number of migrations, with a positive number being migrations to migrate up, and a negative number being migrations to migrate down (IntegerMigrator only).' do |value|
    #   migration_config[:relative] = value.to_i
    # end

    option '-t', '--target [TIMESTAMP]', 'The target version to which to migrate.  If not given, migrates to the maximum version.' do |target_version|
      migration_config[:target] = target_version
    end

    option '-m', '--path-to-migration-patches [DIR_PATH]', "set to check what directory should be used for db migrations (default: #{Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY})" do |new_migration_directory|
      options[:migration_directory] = new_migration_directory
    end

    option '-v', '--verbose', 'set migration to be verbose instead of silent' do
      options[:verbose] = true
    end

    private

    def migration_config
      @migration_config ||= {}
    end

  end
end

Instance Method Details

#runObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rack/app/sequel/runner.rb', line 47

def run
  Sequel.extension(:migration)

  Rack::App::SeQueL.open_connection do |db|
    db.loggers << logger

    run_migrator(db, migration_directory, migration_config)
  end

  return @code
end