Skip to content

Commit 053a555

Browse files
committed
Resolve dependencies to the databases automatically
1 parent 26ce6fa commit 053a555

File tree

10 files changed

+12
-36
lines changed

10 files changed

+12
-36
lines changed

lib/puppet/type/postgresql_psql.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def matches(value)
120120
newvalues(:true, :false)
121121
end
122122

123+
autobefore(:'postgresql::server::database') do
124+
property(:db)
125+
end
126+
123127
def should_run_sql(refreshing = false)
124128
onlyif_param = @parameters[:onlyif]
125129
unless_param = @parameters[:unless]

manifests/server/extension.pp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
}
3434
}
3535

36-
if( $database != 'postgres' ) {
37-
# The database postgres cannot managed by this module, so it is exempt from this dependency
38-
Postgresql_psql {
39-
require => Postgresql::Server::Database[$database],
40-
}
41-
}
42-
4336
postgresql_psql { "${database}: ${command}":
4437

4538
psql_user => $user,

manifests/server/grant.pp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,4 @@
340340
if($role != undef and defined(Postgresql::Server::Role[$role])) {
341341
Postgresql::Server::Role[$role]->Postgresql_psql["grant:${name}"]
342342
}
343-
344-
if($db != undef and defined(Postgresql::Server::Database[$db])) {
345-
Postgresql::Server::Database[$db]->Postgresql_psql["grant:${name}"]
346-
}
347343
}

manifests/server/reassign_owned_by.pp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,4 @@
5454
if($new_role != undef and defined(Postgresql::Server::Role[$new_role])) {
5555
Postgresql::Server::Role[$new_role]->Postgresql_psql["reassign_owned_by:${db}:${sql_command}"]
5656
}
57-
58-
if($db != undef and defined(Postgresql::Server::Database[$db])) {
59-
Postgresql::Server::Database[$db]->Postgresql_psql["reassign_owned_by:${db}:${sql_command}"]
60-
}
6157
}

spec/acceptance/server/grant_role_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class { 'postgresql::server': }
5454
postgresql::server::role { $group:
5555
db => $db,
5656
login => false,
57-
require => Postgresql::Server::Database[$db],
5857
}
5958
6059
# Grant the role to the user
@@ -108,7 +107,6 @@ class { 'postgresql::server': }
108107
postgresql::server::role { $group:
109108
db => $db,
110109
login => false,
111-
require => Postgresql::Server::Database[$db],
112110
}
113111
114112
# Grant the role to the user
@@ -162,7 +160,6 @@ class { 'postgresql::server': }
162160
postgresql::server::role { $group:
163161
db => $db,
164162
login => false,
165-
require => Postgresql::Server::Database[$db],
166163
}
167164
168165
# Grant the role to the user
@@ -199,7 +196,6 @@ class { 'postgresql::server': }
199196
postgresql::server::role { $group:
200197
db => $db,
201198
login => false,
202-
require => Postgresql::Server::Database[$db],
203199
}
204200
205201
# Grant the role to the nonexistent user

spec/acceptance/server/grant_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class { 'postgresql::server': }
3232
# Create a user to grant privileges to
3333
postgresql::server::role { $user:
3434
db => $db,
35-
require => Postgresql::Server::Database[$db],
3635
}
3736
3837
# Make a local user for ident auth
@@ -60,7 +59,6 @@ class { 'postgresql::server': }
6059
db => $db,
6160
psql_user => '#{superuser}',
6261
unless => "SELECT 1 from pg_language where lanname = 'plpgsql'",
63-
require => Postgresql::Server::Database[$db],
6462
}
6563
6664
postgresql::server::grant { 'grant usage on plpgsql':
@@ -139,7 +137,6 @@ class { 'postgresql::server': }
139137
db => $db,
140138
psql_user => $owner,
141139
unless => "SELECT 1 FROM information_schema.sequences WHERE sequence_name = 'test_seq'",
142-
require => Postgresql::Server::Database[$db],
143140
}
144141
145142
postgresql::server::grant { 'grant usage on test_seq':
@@ -160,7 +157,6 @@ class { 'postgresql::server': }
160157
db => $db,
161158
psql_user => $owner,
162159
unless => "SELECT 1 FROM information_schema.sequences WHERE sequence_name = 'test_seq'",
163-
require => Postgresql::Server::Database[$db],
164160
}
165161
166162
postgresql::server::grant { 'grant update on test_seq':
@@ -225,7 +221,6 @@ class { 'postgresql::server': }
225221
db => $db,
226222
psql_user => $owner,
227223
unless => "SELECT 1 FROM information_schema.sequences WHERE sequence_name = 'test_seq2'",
228-
require => Postgresql::Server::Database[$db],
229224
}
230225
231226
postgresql::server::grant { 'grant usage on all sequences':
@@ -247,7 +242,6 @@ class { 'postgresql::server': }
247242
db => $db,
248243
psql_user => $owner,
249244
unless => "SELECT 1 FROM information_schema.sequences WHERE sequence_name = 'test_seq2'",
250-
require => Postgresql::Server::Database[$db],
251245
}
252246
253247
postgresql::server::grant { 'grant usage on all sequences':

spec/acceptance/server/reassign_owned_by_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class { 'postgresql::server': }
2828
# Create a user to reassign ownership to
2929
postgresql::server::role { $new_owner:
3030
db => $db,
31-
require => Postgresql::Server::Database[$db],
3231
}
3332
3433
# Make a local user for ident auth
@@ -80,14 +79,13 @@ class { 'postgresql::server': }
8079
db => '#{db}',
8180
psql_user => '#{old_owner}',
8281
unless => "SELECT tablename FROM pg_catalog.pg_tables WHERE tablename = 'test_tbl'",
83-
require => Postgresql::Server::Database['#{db}'],
8482
}
8583
postgresql_psql { 'create test sequence':
8684
command => 'CREATE SEQUENCE test_seq',
8785
db => '#{db}',
8886
psql_user => '#{old_owner}',
8987
unless => "SELECT relname FROM pg_catalog.pg_class WHERE relkind='S' AND relname = 'test_seq'",
90-
require => [ Postgresql_psql['create test table'], Postgresql::Server::Database['#{db}'] ],
88+
require => Postgresql_psql['create test table'],
9189
}
9290
MANIFEST
9391
end

spec/acceptance/server/schema_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class { 'postgresql::server': }
4848
postgresql::server::schema { $user:
4949
db => $db,
5050
owner => $user,
51-
require => Postgresql::Server::Database[$db],
5251
}
5352
MANIFEST
5453
end

spec/unit/defines/server/db_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
it { is_expected.to contain_postgresql__server__db('test') }
3434
it { is_expected.to contain_postgresql__server__database('test').with_owner('tester') }
35-
it { is_expected.to contain_postgresql__server__role('test').that_comes_before('Postgresql::Server::Database[test]') }
35+
it { is_expected.to contain_postgresql__server__role('test') }
3636
it { is_expected.to contain_postgresql__server__database_grant('GRANT test - ALL - test') }
3737
end
3838

spec/unit/defines/server/extension_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
context 'with mandatory arguments only' do
3131
it {
3232
is_expected.to contain_postgresql_psql('template_postgis: CREATE EXTENSION "postgis"')
33-
.with(db: 'template_postgis', command: 'CREATE EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]')
33+
.with(db: 'template_postgis', command: 'CREATE EXTENSION "postgis"')
3434
}
3535
end
3636

@@ -63,7 +63,7 @@
6363

6464
it {
6565
is_expected.to contain_postgresql_psql('template_postgis: DROP EXTENSION "postgis"')
66-
.with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]')
66+
.with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"')
6767
}
6868

6969
it {
@@ -78,7 +78,7 @@
7878

7979
it {
8080
is_expected.to contain_postgresql_psql('template_postgis: DROP EXTENSION "postgis"')
81-
.with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]')
81+
.with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"')
8282
}
8383

8484
it {
@@ -97,7 +97,7 @@
9797

9898
it {
9999
is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" UPDATE TO \'99.99.99\'')
100-
.with(db: 'template_postgis', unless: "SELECT 1 FROM pg_extension WHERE extname='postgis' AND extversion='99.99.99'").that_requires('Postgresql::Server::Database[template_postgis]')
100+
.with(db: 'template_postgis', unless: "SELECT 1 FROM pg_extension WHERE extname='postgis' AND extversion='99.99.99'")
101101
}
102102
end
103103

@@ -111,7 +111,7 @@
111111
it {
112112
is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" UPDATE')
113113
.with(db: 'template_postgis',
114-
unless: "SELECT 1 FROM pg_available_extensions WHERE name = 'postgis' AND default_version = installed_version").that_requires('Postgresql::Server::Database[template_postgis]')
114+
unless: "SELECT 1 FROM pg_available_extensions WHERE name = 'postgis' AND default_version = installed_version")
115115
}
116116
end
117117
end
@@ -147,7 +147,7 @@
147147
context 'with mandatory arguments only' do
148148
it {
149149
is_expected.to contain_postgresql_psql('template_postgis2: CREATE EXTENSION "postgis"')
150-
.with(db: 'template_postgis2', command: 'CREATE EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis2]')
150+
.with(db: 'template_postgis2', command: 'CREATE EXTENSION "postgis"')
151151
}
152152
end
153153
end

0 commit comments

Comments
 (0)