Skip to content

Commit 7f851e6

Browse files
authored
Merge pull request #891 from jkroepke/3879-import_cat_cmd
Added parameter import_cat_cmd
2 parents 1c763bb + 87efc13 commit 7f851e6

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ mysql::db { 'mydb':
133133
password => 'mypass',
134134
host => 'localhost',
135135
grant => ['SELECT', 'UPDATE'],
136-
sql => '/path/to/sqlfile',
136+
sql => '/path/to/sqlfile.gz',
137+
import_cat_cmd => 'zcat',
137138
import_timeout => 900,
138139
}
139140
```
@@ -820,6 +821,10 @@ Specifies whether to create the database. Valid values are 'present', 'absent'.
820821

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

824+
##### `import_cat_cmd`
825+
826+
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'.
827+
823828
### Types
824829

825830
#### mysql_database
@@ -1030,4 +1035,4 @@ This module is based on work by David Schmitt. The following contributors have c
10301035
* Michael Arnold
10311036
* Chris Weyl
10321037
* Daniël van Eeden
1033-
1038+
* Jan-Otto Kröpke

manifests/db.pp

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$enforce_sql = false,
1212
$ensure = 'present',
1313
$import_timeout = 300,
14+
$import_cat_cmd = 'cat',
1415
) {
1516
#input validation
1617
validate_re($ensure, '^(present|absent)$',
@@ -57,7 +58,7 @@
5758

5859
if $sql {
5960
exec{ "${dbname}-import":
60-
command => "cat ${sql_inputs} | mysql ${dbname}",
61+
command => "${import_cat_cmd} ${sql_inputs} | mysql ${dbname}",
6162
logoutput => true,
6263
environment => "HOME=${::root_home}",
6364
refreshonly => $refresh,

spec/defines/mysql_db_spec.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@
4040
it 'should import sql script on creation if enforcing' do
4141
params.merge!({'sql' => 'test_sql', 'enforce_sql' => true})
4242
is_expected.to contain_exec('test_db-import').with_refreshonly(false)
43-
is_expected.to contain_exec('test_db-import').with_command("cat test_sql | mysql test_db")
43+
is_expected.to contain_exec('test_db-import').with_command('cat test_sql | mysql test_db')
44+
end
45+
46+
it 'should import sql script with custom command on creation if enforcing' do
47+
params.merge!({'sql' => 'test_sql', 'enforce_sql' => true, 'import_cat_cmd' => 'zcat'})
48+
is_expected.to contain_exec('test_db-import').with_refreshonly(false)
49+
is_expected.to contain_exec('test_db-import').with_command('zcat test_sql | mysql test_db')
4450
end
4551

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

0 commit comments

Comments
 (0)