Defined Type: postgresql::schema

Defined in:
manifests/schema.pp

Overview

Parameters:

  • owner (Any)
  • schemaname (Any) (defaults to: $name)
  • port (Any) (defaults to: $postgresql::port)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'manifests/schema.pp', line 1

define postgresql::schema (
                            $owner,
                            $schemaname = $name,
                            $port       = $postgresql::port,
                          ) {

  Postgresql_psql {
    port => $port,
  }

  postgresql_psql { "CREATE SCHEMA ${schemaname}":
    command => "CREATE SCHEMA ${schemaname} AUTHORIZATION ${owner}",
    unless  => "SELECT nspname FROM pg_namespace WHERE nspname='${schemaname}'",
    require => [ Postgresql::Role[$owner], Class['::postgresql::service'] ],
  }

  postgresql_psql { "ALTER SCHEMA ${schemaname} OWNER TO ${owner}":
    command => "ALTER SCHEMA \"${schemaname}\" OWNER TO ${owner}",
    unless  => "SELECT 1 FROM pg_namespace JOIN pg_roles rol ON nspowner = rol.oid WHERE nspname = '${schemaname}' AND rolname = '${owner}'",
    require => Postgresql_psql["CREATE SCHEMA ${schemaname}"],
  }

  if defined(Postgresql::Role[$owner])
  {
    Postgresql::Role[$owner] -> Postgresql_psql["ALTER SCHEMA ${schemaname} OWNER TO ${owner}"]
  }
}