Add is_tt2() like is_json() to database, constraint on atevdef.template collab/senator/schema-is-tt2
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Sat, 13 Oct 2012 16:05:49 +0000 (12:05 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Sat, 13 Oct 2012 16:05:49 +0000 (12:05 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/sql/Pg/002.functions.config.sql
Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.is_tt2.sql [new file with mode: 0644]

index 4f64917..ed431b6 100644 (file)
@@ -402,6 +402,24 @@ CREATE OR REPLACE FUNCTION oils_i18n_gettext( TEXT, TEXT, TEXT, TEXT ) RETURNS T
     SELECT $2;
 $$ LANGUAGE SQL;
 
+CREATE OR REPLACE FUNCTION is_tt2( TEXT ) RETURNS BOOL AS $func$
+use strict;
+use warnings;
+
+use Template;
+use Template::Context;
+
+my $text = shift;
+my $result = Template::Context->new->template(\$text);
+if (defined $result) {
+    return 1;
+} else {
+    warn Template->error;
+    return 0;
+}
+$func$ LANGUAGE plperlu;
+
+
 CREATE OR REPLACE FUNCTION is_json( TEXT ) RETURNS BOOL AS $f$
     use JSON::XS;
     my $json = shift();
index 4701a90..4d4023d 100644 (file)
@@ -187,7 +187,7 @@ CREATE TABLE action_trigger.event_definition (
     opt_in_setting  TEXT        REFERENCES config.usr_setting_type (name) DEFERRABLE INITIALLY DEFERRED,
     delay_field     TEXT,                 -- for instance, xact_start on a circ hook ... look for fields on hook.core_type where datatype=timestamp? If not set, delay from now()
     group_field     TEXT,                 -- field from this.hook.core_type to batch event targets together on, fed into reactor a group at a time.
-    template        TEXT,                 -- the TT block.  will have an 'environment' hash (or array of hashes, grouped events) built up by validator and collector(s), which can be modified.
+    template        TEXT        CHECK ( is_tt2 (template) ),                 -- the TT block.  will have an 'environment' hash (or array of hashes, grouped events) built up by validator and collector(s), which can be modified.
     granularity     TEXT,   -- could specify a batch which is the only time these events should actually run
     CONSTRAINT ev_def_owner_hook_val_react_clean_delay_once UNIQUE (owner, hook, validator, reactor, delay, delay_field),
     CONSTRAINT ev_def_name_owner_once UNIQUE (owner, name)
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.is_tt2.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.is_tt2.sql
new file mode 100644 (file)
index 0000000..fd93463
--- /dev/null
@@ -0,0 +1,26 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION is_tt2( TEXT ) RETURNS BOOL AS $func$
+use strict;
+use warnings;
+
+use Template;
+use Template::Context;
+
+my $text = shift;
+my $result = Template::Context->new->template(\$text);
+if (defined $result) {
+    return 1;
+} else {
+    warn Template->error;
+    return 0;
+}
+$func$ LANGUAGE plperlu;
+
+
+ALTER TABLE action_trigger.event_definition
+    ADD CONSTRAINT template_is_tt2 CHECK ( is_tt2 (template) );
+
+COMMIT;