Skip to content

Commit 8dfba2a

Browse files
authored
Merge pull request #223 from jdsieci/fix_per_database_extensions_schemas
Fixed problems with per database extensions and schemas #140
2 parents 08b9b1a + 6d89542 commit 8dfba2a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

postgres/macros.jinja

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
{%- macro format_state(name, state, kwarg) %}
1414

15-
{%- do kwarg.update({'name': name}) %}
15+
{%- if 'name' not in kwarg %}
16+
{%- do kwarg.update({'name': name}) %}
17+
{%- endif %}
1618
{%- if 'ensure' in kwarg %}
1719
{%- set ensure = kwarg.pop('ensure') %}
1820
{%- endif %}

postgres/manage.sls

+25-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ postgres-reload-modules:
4444
# Database states
4545
4646
{%- for name, db in postgres.databases|dictsort() %}
47+
{%- if 'extensions' in db %}
48+
{%- for ext_name, extension in db.pop('extensions')|dictsort() %}
49+
{%- do extension.update({'name': ext_name, 'maintenance_db': name}) %}
50+
51+
{{ format_state( name + '-' + ext_name, 'postgres_extension', extension) }}
52+
- require:
53+
- postgres_database: postgres_database-{{ name }}
54+
{%- if 'schema' in extension %}
55+
- postgres_schema: postgres_schema-{{ extension.schema }}
56+
{%- endif %}
57+
58+
{%- endfor %}
59+
{%- endif %}
60+
{%- if 'schemas' in db %}
61+
{%- for schema_name, schema in db.pop('schemas')|dictsort() %}
62+
{%- do schema.update({'name': schema_name, 'dbname': name }) %}
63+
64+
{{ format_state( name + '-' + schema_name, 'postgres_schema', schema) }}
65+
- require:
66+
- postgres_database: postgres_database-{{ name }}
67+
68+
{%- endfor %}
69+
{%- endif %}
4770
4871
{{ format_state(name, 'postgres_database', db) }}
4972
{%- if 'owner' in db or 'tablespace' in db %}
@@ -63,8 +86,9 @@ postgres-reload-modules:
6386
{%- for name, schema in postgres.schemas|dictsort() %}
6487
6588
{{ format_state(name, 'postgres_schema', schema) }}
66-
{%- if 'owner' in schema %}
6789
- require:
90+
- postgres_database-{{ schema.dbname }}
91+
{%- if 'owner' in schema %}
6892
- postgres_user: postgres_user-{{ schema.owner }}
6993
{%- endif %}
7094

0 commit comments

Comments
 (0)