Skip to content

Commit 4b29107

Browse files
committed
Simplify extension unless SQL
1 parent 48cb830 commit 4b29107

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

manifests/server/extension.pp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
case $ensure {
1616
'present': {
1717
$command = "CREATE EXTENSION \"${extension}\""
18-
$unless_comp = '='
18+
$unless_mod = ''
1919
$package_require = []
2020
$package_before = Postgresql_psql["Add ${extension} extension to ${database}"]
2121
}
2222

2323
'absent': {
2424
$command = "DROP EXTENSION \"${extension}\""
25-
$unless_comp = '!='
25+
$unless_mod = 'NOT '
2626
$package_require = Postgresql_psql["Add ${extension} extension to ${database}"]
2727
$package_before = []
2828
}
@@ -48,7 +48,7 @@
4848

4949
db => $database,
5050
command => $command,
51-
unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = '${extension}') as t WHERE t.count ${unless_comp} 1",
51+
unless => "SELECT 1 WHERE ${unless_mod}EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extension}')",
5252
}
5353

5454
if $package_name {

spec/unit/defines/server/extension_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis').with({
3131
:db => 'template_postgis',
3232
:command => 'CREATE EXTENSION "postgis"',
33-
:unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count = 1",
3433
}).that_requires('Postgresql::Server::Database[template_postgis]')
3534
}
3635
end
@@ -58,7 +57,6 @@
5857
is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis').with({
5958
:db => 'template_postgis',
6059
:command => 'DROP EXTENSION "postgis"',
61-
:unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count != 1",
6260
}).that_requires('Postgresql::Server::Database[template_postgis]')
6361
}
6462

@@ -78,7 +76,6 @@
7876
is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis').with({
7977
:db => 'template_postgis',
8078
:command => 'DROP EXTENSION "postgis"',
81-
:unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count != 1",
8279
}).that_requires('Postgresql::Server::Database[template_postgis]')
8380
}
8481

@@ -153,7 +150,6 @@
153150
is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis2').with({
154151
:db => 'template_postgis2',
155152
:command => 'CREATE EXTENSION "postgis"',
156-
:unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count = 1",
157153
}).that_requires('Postgresql::Server::Database[template_postgis2]')
158154
}
159155
end

0 commit comments

Comments
 (0)