Skip to content

Commit 887a0a9

Browse files
committed
Improve style of the database resource
1 parent f6ef841 commit 887a0a9

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

manifests/server/database.pp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@
8181

8282
# This will prevent users from connecting to the database unless they've been
8383
# granted privileges.
84-
~> postgresql_psql { "REVOKE ${public_revoke_privilege} ON DATABASE \"${dbname}\" FROM public":
84+
postgresql_psql { "REVOKE ${public_revoke_privilege} ON DATABASE \"${dbname}\" FROM public":
8585
refreshonly => true,
86+
subscribe => Postgresql_psql["CREATE DATABASE \"${dbname}\""],
8687
}
8788

88-
Postgresql_psql["CREATE DATABASE \"${dbname}\""]
89-
-> postgresql_psql { "UPDATE pg_database SET datistemplate = ${istemplate} WHERE datname = '${dbname}'":
90-
unless => "SELECT 1 FROM pg_database WHERE datname = '${dbname}' AND datistemplate = ${istemplate}",
89+
postgresql_psql { "UPDATE pg_database SET datistemplate = ${istemplate} WHERE datname = '${dbname}'":
90+
unless => "SELECT 1 FROM pg_database WHERE datname = '${dbname}' AND datistemplate = ${istemplate}",
91+
require => Postgresql_psql["CREATE DATABASE \"${dbname}\""],
9192
}
9293

9394
if $comment {
@@ -96,10 +97,11 @@
9697
'8.1' => 'obj_description',
9798
default => 'shobj_description',
9899
}
99-
Postgresql_psql["CREATE DATABASE \"${dbname}\""]
100-
-> postgresql_psql { "COMMENT ON DATABASE \"${dbname}\" IS '${comment}'":
101-
unless => "SELECT 1 FROM pg_catalog.pg_database d WHERE datname = '${dbname}' AND pg_catalog.${comment_information_function}(d.oid, 'pg_database') = '${comment}'",
102-
db => $dbname,
100+
101+
postgresql_psql { "COMMENT ON DATABASE \"${dbname}\" IS '${comment}'":
102+
unless => "SELECT 1 FROM pg_catalog.pg_database d WHERE datname = '${dbname}' AND pg_catalog.${comment_information_function}(d.oid, 'pg_database') = '${comment}'",
103+
db => $dbname,
104+
require => Postgresql_psql["CREATE DATABASE \"${dbname}\""],
103105
}
104106
}
105107

@@ -109,9 +111,7 @@
109111
require => Postgresql_psql["CREATE DATABASE \"${dbname}\""],
110112
}
111113

112-
if defined(Postgresql::Server::Role[$owner]) {
113-
Postgresql::Server::Role[$owner]->Postgresql_psql["ALTER DATABASE \"${dbname}\" OWNER TO \"${owner}\""]
114-
}
114+
Postgresql::Server::Role <| username == $owner |> -> Postgresql_psql["ALTER DATABASE \"${dbname}\" OWNER TO \"${owner}\""]
115115
}
116116

117117
if $tablespace {
@@ -120,9 +120,6 @@
120120
require => Postgresql_psql["CREATE DATABASE \"${dbname}\""],
121121
}
122122

123-
if defined(Postgresql::Server::Tablespace[$tablespace]) {
124-
# The tablespace must be there, before we create the database.
125-
Postgresql::Server::Tablespace[$tablespace]->Postgresql_psql["CREATE DATABASE \"${dbname}\""]
126-
}
123+
Postgresql::Server::Tablespace <| spcname == $tablespace |> -> Postgresql_psql["CREATE DATABASE \"${dbname}\""]
127124
}
128125
}

0 commit comments

Comments
 (0)