1 Puppet::Type.newtype(:postgresql_psql) do
4 desc "An arbitrary tag for your own reference; the name of the message."
8 newproperty(:command) do
9 desc 'The SQL command to execute via psql.'
11 defaultto { @resource[:name] }
13 def sync(refreshing = false)
14 # We're overriding 'sync' here in order to do some magic
15 # in support of providing a 'refreshonly' parameter. This
16 # is kind of hacky because the logic for 'refreshonly' is
17 # spread between the type and the provider, but this is
18 # the least horrible way that I could determine to accomplish
21 # Note that our overridden version of 'sync' takes a parameter,
22 # 'refreshing', which the parent version doesn't take. This
23 # allows us to call the sync method directly from the 'refresh'
24 # method, and then inside of the body of 'sync' we can tell
25 # whether or not we're refreshing.
27 if ((@resource[:refreshonly] == :false) || refreshing)
28 # If we're not in 'refreshonly' mode, or we're not currently
29 # refreshing, then we just call the parent method.
32 # If we get here, it means we're in 'refreshonly' mode and
33 # we're not being called by the 'refresh' method, so we
34 # just no-op. We'll be called again by the 'refresh'
42 desc "An optional SQL command to execute prior to the main :command; " +
43 "this is generally intended to be used for idempotency, to check " +
44 "for the existence of an object in the database to determine whether " +
45 "or not the main SQL command needs to be executed at all."
49 desc "The name of the database to execute the SQL command against."
52 newparam(:psql_path) do
53 desc "The path to psql executable."
57 newparam(:psql_user) do
58 desc "The system user account under which the psql command should be executed."
62 newparam(:psql_group) do
63 desc "The system user group account under which the psql command should be executed."
67 newparam(:cwd, :parent => Puppet::Parameter::Path) do
68 desc "The working directory under which the psql command should be executed."
72 newparam(:refreshonly) do
73 desc "If 'true', then the SQL will only be executed via a notify/subscribe event."
79 # All of the magic for this type is attached to the ':command' property, so
80 # we just need to sync it to accomplish a 'refresh'.
81 self.property(:command).sync(true)