X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44..53593baa211863fbf66540cf1bcc36c8fb37257f:/sql/Pg-upgrade2/custom_data_export.sql

diff --git a/sql/Pg-upgrade2/custom_data_export.sql b/sql/Pg-upgrade2/custom_data_export.sql
new file mode 100644
index 000000000..b5959329a
--- /dev/null
+++ b/sql/Pg-upgrade2/custom_data_export.sql
@@ -0,0 +1,37 @@
+-- @tag: custom_data_export
+-- @description: Benutzerdefinierter Datenexport
+-- @depends: release_3_5_0
+CREATE TYPE custom_data_export_query_parameter_type_enum AS ENUM ('text', 'number', 'date', 'timestamp');
+
+CREATE TABLE custom_data_export_queries (
+  id           SERIAL,
+  name         TEXT      NOT NULL,
+  description  TEXT      NOT NULL,
+  sql_query    TEXT      NOT NULL,
+  access_right TEXT,
+  itime        TIMESTAMP NOT NULL DEFAULT now(),
+  mtime        TIMESTAMP NOT NULL DEFAULT now(),
+
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE custom_data_export_query_parameters (
+  id             SERIAL,
+  query_id       INTEGER NOT NULL,
+  name           TEXT NOT NULL,
+  description    TEXT,
+  parameter_type custom_data_export_query_parameter_type_enum NOT NULL,
+  itime          TIMESTAMP NOT NULL DEFAULT now(),
+  mtime          TIMESTAMP NOT NULL DEFAULT now(),
+
+  PRIMARY KEY (id),
+  FOREIGN KEY (query_id) REFERENCES custom_data_export_queries (id) ON DELETE CASCADE
+);
+
+CREATE TRIGGER mtime_custom_data_export_queries
+BEFORE UPDATE ON custom_data_export_queries
+FOR EACH ROW EXECUTE PROCEDURE set_mtime();
+
+CREATE TRIGGER mtime_custom_data_export_query_parameters
+BEFORE UPDATE ON custom_data_export_query_parameters
+FOR EACH ROW EXECUTE PROCEDURE set_mtime();
