LP#847973 ensure JSON values for org settings
authorJason Etheridge <jason@esilibrary.com>
Mon, 12 Sep 2011 15:29:51 +0000 (11:29 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Tue, 18 Oct 2011 13:50:22 +0000 (09:50 -0400)
I don't believe you can violate this constraint via the Library Settings UI,
but this will catch speedy-admins mucking directly in the database.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/sql/Pg/005.schema.actors.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_setting_json_check.sql [new file with mode: 0644]

index 4306245..3f8fb92 100644 (file)
@@ -457,7 +457,8 @@ CREATE TABLE actor.org_unit_setting (
        org_unit        INT             NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
        name            TEXT    NOT NULL REFERENCES config.org_unit_setting_type DEFERRABLE INITIALLY DEFERRED,
        value           TEXT            NOT NULL,
-       CONSTRAINT ou_once_per_key UNIQUE (org_unit,name)
+       CONSTRAINT ou_once_per_key UNIQUE (org_unit,name),
+       CONSTRAINT aous_must_be_json CHECK ( evergreen.is_json(value) )
 );
 COMMENT ON TABLE actor.org_unit_setting IS $$
 Org Unit settings
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_setting_json_check.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_setting_json_check.sql
new file mode 100644 (file)
index 0000000..0e96020
--- /dev/null
@@ -0,0 +1,11 @@
+-- Evergreen DB patch XXXX.schema.org_unit_setting_json_check.sql
+--
+--
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE actor.org_unit_setting ADD CONSTRAINT aous_must_be_json CHECK ( evergreen.is_json(value) );
+
+COMMIT;