1 # Define: postgresql::db
3 # This module creates database instances, a user, and grants that user
4 # privileges to the database.
6 # Since it requires class postgresql::server, we assume to run all commands as the
7 # postgresql user against the local postgresql server.
9 # TODO: support an array of privileges for "grant"; currently only supports a single
10 # privilege, which is pretty useless unless that privilege is "ALL"
13 # [*title*] - postgresql database name.
14 # [*user*] - username to create and grant access.
15 # [*password*] - user's password. may be md5-encoded, in the format returned by the "postgresql_password"
16 # function in this module
17 # [*charset*] - database charset. defaults to 'utf8'
18 # [*grant*] - privilege to grant user. defaults to 'all'.
19 # [*tablespace*] - database tablespace. default to use the template database's tablespace.
20 # [*locale*] - locale for database. defaults to 'undef' (effectively 'C').
26 # class postgresql::server
30 # postgresql::db { 'mydb':
32 # password => 'password',
36 define postgresql::db (
39 $charset = $postgresql::params::charset,
40 $locale = $postgresql::params::locale,
45 include postgresql::params
47 postgresql::database { $name:
48 # TODO: ensure is not yet supported
51 tablespace => $tablespace,
52 #provider => 'postgresql',
53 require => Class['postgresql::server'],
55 istemplate => $istemplate,
58 if ! defined(Postgresql::Database_user[$user]) {
59 postgresql::database_user { $user:
60 # TODO: ensure is not yet supported
62 password_hash => $password,
63 #provider => 'postgresql',
64 require => Postgresql::Database[$name],
68 postgresql::database_grant { "GRANT ${user} - ${grant} - ${name}":
72 #provider => 'postgresql',
73 require => [Postgresql::Database[$name], Postgresql::Database_user[$user]],