Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ group :development, :test do
gem 'puppetlabs_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', :require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
end
Expand Down
6 changes: 3 additions & 3 deletions manifests/flyway.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
include ::java
Class['::java'] -> Database_schema::Flyway_migration<||>
}

archive { "flyway-commandline-${version}":
ensure => $ensure,
url => $real_source,
target => $target_dir,
root_dir => "flyway-${version}",
checksum => false
}

Class['database_schema::flyway'] -> Database_schema::Flyway_migration<||>
}
}
26 changes: 16 additions & 10 deletions manifests/flyway_migration.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,50 @@
# Version number to migrate up to (see the migrate option "target" in the flyway docs). Defaults to "latest"
# [*placeholders*]
# A hash containing placeholders you want flyway to use. Each key expands to a "-placeholder.KEY='VALUE'" argument to flyway.
# [*timeout*]
# The maximum time the migration should take in seconds. This gets passed directly to the migration Exec resource. Defaults to 300.
#
define database_schema::flyway_migration (
$schema_source,
$db_username,
$db_password,
$jdbc_url,
$flyway_path = '/opt/flyway-3.1',
$target_schemas = undef,
$ensure = latest,
$placeholders = {},
$flyway_path = '/opt/flyway-3.1',
$target_schemas = undef,
$ensure = latest,
$placeholders = {},
$timeout = 300,
){
validate_integer($timeout)
validate_hash($placeholders)

$title_hash = sha1($title)
$staging_path = "/tmp/flyway-migration-${title_hash}"
file { $staging_path:
ensure => directory,
recurse => true,
source => $schema_source
}

validate_hash($placeholders)

$placeholders_str = flyway_cmd_placeholders($placeholders)

$target_version = $ensure ? {latest => '', default => " -target=${ensure}"}
$flyway_base_command = "flyway -user='${db_username}' -password='${db_password}' -url='${jdbc_url}' ${placeholders_str} -locations='filesystem:${staging_path}'$target_version"
$flyway_base_command = "flyway -user='${db_username}' -password='${db_password}' -url='${jdbc_url}' ${placeholders_str} -locations='filesystem:${staging_path}'${target_version}"

if $target_schemas == undef {
$flyway_command = $flyway_base_command
}
else {
$joined_schemas = join($target_schemas, ',')
$flyway_command = "${flyway_base_command} -schemas='${joined_schemas}'"
}

exec { "Migration for ${title}":
cwd => $flyway_path,
path => "${flyway_path}:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin",
unless => "${flyway_command} validate",
command => "${flyway_command} migrate",
require => File[$staging_path]
timeout => $timeout,
require => File[$staging_path],
}
}
12 changes: 6 additions & 6 deletions manifests/liquibase.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@
undef => "http://repo1.maven.org/maven2/org/liquibase/liquibase-core/${version}/liquibase-core-${version}-bin.tar.gz",
default => $source
}

$dir_ensure = $ensure ? {
absent => absent,
default => directory
}

if $ensure == present and $manage_java {
include ::java
Class['::java'] -> Database_schema::Liquibase_migration<||>
}

file { "${target_dir}/liquibase":
ensure => $dir_ensure,
force => true
}

archive { "liquibase-core-${version}-bin":
ensure => $ensure,
url => $real_source,
target => "${target_dir}/liquibase",
root_dir => 'liquibase',
checksum => false
}

Class['database_schema::liquibase'] -> Database_schema::Liquibase_migration<||>
}
}
22 changes: 14 additions & 8 deletions manifests/liquibase_migration.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
# Default schema to apply migrations to.
# [*ensure*]
# Only supported value is "latest".
# [*timeout*]
# The maximum time the migration should take in seconds. This gets passed directly to the migration Exec resource. Defaults to 300.
#
define database_schema::liquibase_migration (
$changelog_source,
$db_username,
$db_password,
$jdbc_url,
$liquibase_path = '/opt/liquibase',
$default_schema = undef,
$ensure = latest
$liquibase_path = '/opt/liquibase',
$default_schema = undef,
$ensure = latest,
$timeout = 300,
){
validate_integer($timeout)

$title_hash = sha1(title)
$changelog_basename = inline_template('<%= File.basename(@changelog_source) %>')
$staging_path = "/tmp/liquibase-migration-${title_hash}"
Expand All @@ -40,21 +45,22 @@
ensure => present,
source => $changelog_source
}

$liquibase_base_command = "liquibase --username='${db_username}' --password='${db_password}' --url='${jdbc_url}' --changeLogFile='${changelog_path}'"

if $default_schema == undef {
$flyway_command = $liquibase_base_command
}
else {
$flyway_command = "${liquibase_base_command} --defaultSchemaNAme='${default_schema}'"
}

exec { "Migration for ${title}":
cwd => $liquibase_path,
path => "${liquibase_path}:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin",
onlyif => "${flyway_command} status | grep 'change sets have not been applied'",
command => "${flyway_command} update",
require => File[$changelog_path]
timeout => $timeout,
require => File[$changelog_path],
}
}
}
4 changes: 2 additions & 2 deletions spec/classes/flyway_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'database_schema::flyway' do
let(:facts){{:operatingsystem => 'RedHat', :osfamily => 'RedHat'}}
let(:facts){{:operatingsystem => 'RedHat', :osfamily => 'RedHat', :operatingsystemrelease => '7'}}
include_examples :compile
end
end
4 changes: 2 additions & 2 deletions spec/classes/liquibase_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'database_schema::liquibase' do
let(:facts){{:operatingsystem => 'RedHat', :osfamily => 'RedHat'}}
let(:facts){{:operatingsystem => 'RedHat', :osfamily => 'RedHat', :operatingsystemrelease => '7'}}
include_examples :compile
end
end
19 changes: 19 additions & 0 deletions spec/defines/flyway_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@
end
end
end
describe 'timeout' do
context 'when not specified' do
it 'exec has timeout set to 300 seconds' do
is_expected.to contain_exec('Migration for example db').with_timeout(300)
end
end
context 'when specified' do
let(:params){{
:schema_source => '/some/path',
:db_username => 'user',
:db_password => 'supersecret',
:jdbc_url => 'jdbc:h2:test',
:timeout => 3600
}}
it 'passes timeout to exec' do
is_expected.to contain_exec('Migration for example db').with_timeout(3600)
end
end
end
end
21 changes: 20 additions & 1 deletion spec/defines/liquibase_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,23 @@
:jdbc_url => 'jdbc:h2:test'
}}
include_examples :compile
end
describe 'timeout' do
context 'when not specified' do
it 'exec has timeout set to 300 seconds' do
is_expected.to contain_exec('Migration for example db').with_timeout(300)
end
end
context 'when specified' do
let(:params){{
:changelog_source => '/some/path',
:db_username => 'user',
:db_password => 'supersecret',
:jdbc_url => 'jdbc:h2:test',
:timeout => 3600
}}
it 'passes timeout to exec' do
is_expected.to contain_exec('Migration for example db').with_timeout(3600)
end
end
end
end