class Pgtk::LiquibaseTask

Liquibase rake task.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2019 Yegor Bugayenko

License

MIT

Attributes

master[RW]
name[RW]
quiet[RW]
yaml[RW]

Public Class Methods

new(*args) { |*[self, task_args].slice(0, arity)| ... } click to toggle source
# File lib/pgtk/liquibase_task.rb, line 40
def initialize(*args, &task_block)
  @name = args.shift || :liquibase
  @quite = false
  unless ::Rake.application.last_description
    desc 'Deploy Liquibase changes to the running PostgreSQL server'
  end
  task(name, *args) do |_, task_args|
    RakeFileUtils.send(:verbose, true) do
      yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
      run
    end
  end
end

Private Instance Methods

run() click to toggle source
# File lib/pgtk/liquibase_task.rb, line 56
def run
  raise "Option 'master' is mandatory" unless @master
  raise "Option 'yaml' is mandatory" unless @yaml
  yml = YAML.load_file(
    if @yaml.is_a?(Array)
      @yaml.drop_while { |f| !File.exist?(f) }.first
    else
      @yaml
    end
  )
  raise "YAML at #{yaml} is missing 'pgsql' section" unless yml['pgsql']
  pom = File.expand_path(File.join(__dir__, '../../resources/pom.xml'))
  raise "Liquibase master is absent at #{@master}" unless File.exist?(@master)
  @master = File.expand_path(@master)
  Dir.chdir(File.dirname(@master)) do
    system(
      [
        'mvn verify',
        '--errors',
        '--batch-mode',
        @quiet ? '--quiet' : '',
        '--file',
        Shellwords.escape(pom),
        '--define',
        "liquibase.changeLogFile=#{@master}",
        '--define',
        "liquibase.url=#{Shellwords.escape(yml['pgsql']['url'])}",
        '--define',
        "liquibase.password=#{Shellwords.escape(yml['pgsql']['password'])}",
        '--define',
        "liquibase.logging=#{@quiet ? 'severe' : 'info'}",
        '2>&1'
      ].join(' ')
    )
  end
  raise unless $CHILD_STATUS.exitstatus.zero?
end