Merge pull request #223 from jdsieci/fix_per_database_extensions_schemas

Fixed problems with per database extensions and schemas #140
This commit is contained in:
Niels Abspoel 2018-07-29 16:56:36 +02:00 committed by GitHub
commit 8dfba2abdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View file

@ -12,7 +12,9 @@
{%- macro format_state(name, state, kwarg) %}
{%- if 'name' not in kwarg %}
{%- do kwarg.update({'name': name}) %}
{%- endif %}
{%- if 'ensure' in kwarg %}
{%- set ensure = kwarg.pop('ensure') %}
{%- endif %}

View file

@ -44,6 +44,29 @@ postgres-reload-modules:
# Database states
{%- for name, db in postgres.databases|dictsort() %}
{%- if 'extensions' in db %}
{%- for ext_name, extension in db.pop('extensions')|dictsort() %}
{%- do extension.update({'name': ext_name, 'maintenance_db': name}) %}
{{ format_state( name + '-' + ext_name, 'postgres_extension', extension) }}
- require:
- postgres_database: postgres_database-{{ name }}
{%- if 'schema' in extension %}
- postgres_schema: postgres_schema-{{ extension.schema }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if 'schemas' in db %}
{%- for schema_name, schema in db.pop('schemas')|dictsort() %}
{%- do schema.update({'name': schema_name, 'dbname': name }) %}
{{ format_state( name + '-' + schema_name, 'postgres_schema', schema) }}
- require:
- postgres_database: postgres_database-{{ name }}
{%- endfor %}
{%- endif %}
{{ format_state(name, 'postgres_database', db) }}
{%- if 'owner' in db or 'tablespace' in db %}
@ -63,8 +86,9 @@ postgres-reload-modules:
{%- for name, schema in postgres.schemas|dictsort() %}
{{ format_state(name, 'postgres_schema', schema) }}
{%- if 'owner' in schema %}
- require:
- postgres_database-{{ schema.dbname }}
{%- if 'owner' in schema %}
- postgres_user: postgres_user-{{ schema.owner }}
{%- endif %}