Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problems with per database extensions and schemas #140 #223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion postgres/macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

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

{%- do kwarg.update({'name': name}) %}
{%- if 'name' not in kwarg %}
{%- do kwarg.update({'name': name}) %}
{%- endif %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just awesome. Would mind to update pillar.example file for the formula users to see they now able to provide unique IDs for PG entities?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't set state id via pillar. So no need for pillar.example update. This feature is for formula developers only.
IMHO Allowing user setting state ids is asking for trouble.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t0fik No-no, it is not about setting state IDs. There was PR #155 that intended to add capability to override PG entity attributes (including names) depending on some external data. But it wasn't merged. With your changes, it is also achievable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vutny Nice to hear that.

{%- if 'ensure' in kwarg %}
{%- set ensure = kwarg.pop('ensure') %}
{%- endif %}
Expand Down
26 changes: 25 additions & 1 deletion postgres/manage.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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 %}

Expand Down