Class: SchemaEvolutionManager::ApplyUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/schema-evolution-manager/apply_util.rb

Instance Method Summary collapse

Constructor Details

#initialize(db, opts = {}) ⇒ ApplyUtil

Returns a new instance of ApplyUtil.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/schema-evolution-manager/apply_util.rb', line 5

def initialize(db, opts={})
  @dry_run = opts.delete(:dry_run)
  if @dry_run.nil?
    @dry_run = true
  end

  @non_interactive = opts.delete(:non_interactive)
  if @non_interactive.nil?
    @non_interactive = false
  end

  @db = Preconditions.assert_class(db, Db)
  @scripts = Scripts.new(@db, Scripts::SCRIPTS)
end

Instance Method Details

#apply!(dir) ⇒ Object

Applies scripts in order, returning number of scripts applied



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
# File 'lib/schema-evolution-manager/apply_util.rb', line 29

def apply!(dir)
  Preconditions.check_state(File.directory?(dir),
                            "Dir[%s] does not exist" % dir)

  pending_scripts = []
  @scripts.each_pending(dir) do |filename, path|
    pending_scripts << [filename, path]
  end

  if pending_scripts.size > 1 && !dry_run? && !non_interactive?
    puts "Please confirm that you would like to apply all (#{pending_scripts.size}) of the pending scripts:"
    pending_scripts.each do |filename, path|
      puts "  #{filename}"
    end
    continue = SchemaEvolutionManager::Ask.for_boolean("Continue?")
    if !continue
      return 0
    end
  end

  pending_scripts.each do |filename, path|
    if @dry_run
      puts "[DRY RUN] Applying #{filename}"
      puts path
      puts ""
    else
      print "Applying #{filename}"
      @db.psql_file(filename, path)
      @scripts.record_as_run!(filename)
      puts " Done"
    end
  end
  pending_scripts.size
end

#dry_run?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/schema-evolution-manager/apply_util.rb', line 20

def dry_run?
  @dry_run
end

#non_interactive?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/schema-evolution-manager/apply_util.rb', line 24

def non_interactive?
  @non_interactive
end