Add actual postgresl module from puppetlabs
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / lib / puppet / type / postgresql_psql.rb
1 Puppet::Type.newtype(:postgresql_psql) do
2
3   newparam(:name) do
4     desc "An arbitrary tag for your own reference; the name of the message."
5     isnamevar
6   end
7
8   newproperty(:command) do
9     desc 'The SQL command to execute via psql.'
10
11     defaultto { @resource[:name] }
12
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
19       # it.
20       #
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.
26
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.
30         super()
31       else
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'
35         # method momentarily.
36         nil
37       end
38     end
39   end
40
41   newparam(:unless) do
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."
46   end
47
48   newparam(:db) do
49     desc "The name of the database to execute the SQL command against."
50   end
51
52   newparam(:psql_path) do
53     desc "The path to psql executable."
54     defaultto("psql")
55   end
56
57   newparam(:psql_user) do
58     desc "The system user account under which the psql command should be executed."
59     defaultto("postgres")
60   end
61
62   newparam(:psql_group) do
63     desc "The system user group account under which the psql command should be executed."
64     defaultto("postgres")
65   end
66
67   newparam(:cwd, :parent => Puppet::Parameter::Path) do
68     desc "The working directory under which the psql command should be executed."
69     defaultto("/tmp")
70   end
71
72   newparam(:refreshonly) do
73     desc "If 'true', then the SQL will only be executed via a notify/subscribe event."
74
75     defaultto(:false)
76   end
77
78   def refresh()
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)
82   end
83
84 end