Add support for simple queries
diff --git a/README.rst b/README.rst
index 6685805..bc85b8f 100644
--- a/README.rst
+++ b/README.rst
@@ -296,6 +296,11 @@
host: localhost
createdb: true
rights: all privileges
+ init:
+ maintenance_db: mydb
+ queries:
+ - INSERT INTO login VALUES (11, 1) ;
+ - INSERT INTO device VALUES (1, 11, 42);
Sample usage
diff --git a/postgresql/_database.sls b/postgresql/_database.sls
index b6ff3cc..6e1d32c 100644
--- a/postgresql/_database.sls
+++ b/postgresql/_database.sls
@@ -39,6 +39,24 @@
- user: root
{%- endif %}
+{%- if database.init is defined %}
+{%- for query in database.init.get('queries', []) %}
+{% set maintenance_db = database.init.get('maintenance_db', database_name) %}
+postgresql_database_{{ svr_name|default('localhost') }}_{{ maintenance_db }}_{{ loop.index }}:
+ cmd.run:
+ - name: "psql -h {{ admin.get('host', 'localhost') }} \
+ -U {{ admin.get('user', 'root') }} \
+ -d {{ maintenance_db }} \
+ -c \"{{ query }} \" "
+ env:
+ PGPASSWORD: {{ admin.get('password', '') }}
+ {%- if not database.init.get('force', false) == true %}
+ onchanges:
+ - postgres_database: postgresql_database_{{ svr_name|default('localhost') }}_{{ maintenance_db }}
+ {%- endif %}
+{%- endfor %}
+{%- endif %}
+
{%- if database.initial_data is defined %}
{%- set engine = database.initial_data.get("engine", "backupninja") %}