2012-06-09 18:23:11 +02:00
|
|
|
# Define: postgresql::db
|
|
|
|
#
|
|
|
|
# This module creates database instances, a user, and grants that user
|
|
|
|
# privileges to the database.
|
|
|
|
#
|
|
|
|
# Since it requires class postgresql::server, we assume to run all commands as the
|
|
|
|
# postgresql user against the local postgresql server.
|
|
|
|
#
|
|
|
|
# TODO: support an array of privileges for "grant"; currently only supports a single
|
|
|
|
# privilege, which is pretty useless unless that privilege is "ALL"
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# [*title*] - postgresql database name.
|
|
|
|
# [*user*] - username to create and grant access.
|
|
|
|
# [*password*] - user's password. may be md5-encoded, in the format returned by the "postgresql_password"
|
|
|
|
# function in this module
|
2013-01-16 01:09:10 +01:00
|
|
|
# [*charset*] - database charset. defaults to 'utf8'
|
|
|
|
# [*grant*] - privilege to grant user. defaults to 'all'.
|
2013-01-28 18:01:11 +01:00
|
|
|
# [*tablespace*] - database tablespace. default to use the template database's tablespace.
|
2013-02-02 02:54:33 +01:00
|
|
|
# [*locale*] - locale for database. defaults to 'undef' (effectively 'C').
|
2012-06-09 18:23:11 +02:00
|
|
|
#
|
|
|
|
# Actions:
|
|
|
|
#
|
|
|
|
# Requires:
|
|
|
|
#
|
|
|
|
# class postgresql::server
|
|
|
|
#
|
|
|
|
# Sample Usage:
|
|
|
|
#
|
|
|
|
# postgresql::db { 'mydb':
|
|
|
|
# user => 'my_user',
|
|
|
|
# password => 'password',
|
|
|
|
# grant => 'all'
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
define postgresql::db (
|
|
|
|
$user,
|
|
|
|
$password,
|
2013-02-02 02:54:33 +01:00
|
|
|
$charset = $postgresql::params::charset,
|
|
|
|
$locale = $postgresql::params::locale,
|
2013-01-28 18:01:11 +01:00
|
|
|
$grant = 'ALL',
|
2013-02-02 02:54:33 +01:00
|
|
|
$tablespace = undef
|
|
|
|
) {
|
|
|
|
include postgresql::params
|
2012-06-09 18:23:11 +02:00
|
|
|
|
|
|
|
postgresql::database { $name:
|
|
|
|
# TODO: ensure is not yet supported
|
|
|
|
#ensure => present,
|
|
|
|
charset => $charset,
|
2013-01-28 18:01:11 +01:00
|
|
|
tablespace => $tablespace,
|
2012-06-09 18:23:11 +02:00
|
|
|
#provider => 'postgresql',
|
|
|
|
require => Class['postgresql::server'],
|
2013-02-02 02:54:33 +01:00
|
|
|
locale => $locale,
|
2012-06-09 18:23:11 +02:00
|
|
|
}
|
|
|
|
|
2012-11-08 19:50:08 +01:00
|
|
|
if ! defined(Postgresql::Database_user[$user]) {
|
|
|
|
postgresql::database_user { $user:
|
|
|
|
# TODO: ensure is not yet supported
|
|
|
|
#ensure => present,
|
|
|
|
password_hash => $password,
|
|
|
|
#provider => 'postgresql',
|
|
|
|
require => Postgresql::Database[$name],
|
|
|
|
}
|
2012-06-09 18:23:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
postgresql::database_grant { "GRANT ${user} - ${grant} - ${name}":
|
|
|
|
privilege => $grant,
|
|
|
|
db => $name,
|
|
|
|
role => $user,
|
|
|
|
#provider => 'postgresql',
|
2012-12-06 23:35:42 +01:00
|
|
|
require => [Postgresql::Database[$name], Postgresql::Database_user[$user]],
|
2012-06-09 18:23:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|