Skip to content

Added parameter import_cat_cmd #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2016
Merged
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ mysql::db { 'mydb':
password => 'mypass',
host => 'localhost',
grant => ['SELECT', 'UPDATE'],
sql => '/path/to/sqlfile',
sql => '/path/to/sqlfile.gz',
import_cat_cmd => 'zcat',
import_timeout => 900,
}
```
Expand Down Expand Up @@ -820,6 +821,10 @@ Specifies whether to create the database. Valid values are 'present', 'absent'.

Timeout, in seconds, for loading the sqlfiles. Defaults to '300'.

##### `import_cat_cmd`

Command to read the sqlfile for importing the database. Useful for compressed sqlfiles. For example, you can use 'zcat' for .gz files. Defaults to 'cat'.

### Types

#### mysql_database
Expand Down Expand Up @@ -1029,4 +1034,4 @@ This module is based on work by David Schmitt. The following contributors have c
* Michael Arnold
* Chris Weyl
* Daniël van Eeden

* Jan-Otto Kröpke
3 changes: 2 additions & 1 deletion manifests/db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$enforce_sql = false,
$ensure = 'present',
$import_timeout = 300,
$import_cat_cmd = 'cat',
) {
#input validation
validate_re($ensure, '^(present|absent)$',
Expand Down Expand Up @@ -57,7 +58,7 @@

if $sql {
exec{ "${dbname}-import":
command => "cat ${sql_inputs} | mysql ${dbname}",
command => "${import_cat_cmd} ${sql_inputs} | mysql ${dbname}",
logoutput => true,
environment => "HOME=${::root_home}",
refreshonly => $refresh,
Expand Down
8 changes: 7 additions & 1 deletion spec/defines/mysql_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@
it 'should import sql script on creation if enforcing' do
params.merge!({'sql' => 'test_sql', 'enforce_sql' => true})
is_expected.to contain_exec('test_db-import').with_refreshonly(false)
is_expected.to contain_exec('test_db-import').with_command("cat test_sql | mysql test_db")
is_expected.to contain_exec('test_db-import').with_command('cat test_sql | mysql test_db')
end

it 'should import sql script with custom command on creation if enforcing' do
params.merge!({'sql' => 'test_sql', 'enforce_sql' => true, 'import_cat_cmd' => 'zcat'})
is_expected.to contain_exec('test_db-import').with_refreshonly(false)
is_expected.to contain_exec('test_db-import').with_command('zcat test_sql | mysql test_db')
end

it 'should import sql scripts when more than one is specified' do
Expand Down