From e4b1f26c84f090b1ccc2c56681ac3bff40e1b7d8 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Mon, 12 Sep 2011 11:29:51 -0400 Subject: [PATCH] LP#847973 ensure JSON values for org settings 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 Signed-off-by: Thomas Berezansky --- Open-ILS/src/sql/Pg/005.schema.actors.sql | 3 ++- .../Pg/upgrade/XXXX.schema.org_unit_setting_json_check.sql | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_setting_json_check.sql diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql index 430624571f..3f8fb920f7 100644 --- a/Open-ILS/src/sql/Pg/005.schema.actors.sql +++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql @@ -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 index 0000000000..0e96020bae --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_setting_json_check.sql @@ -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; -- 2.11.0