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>
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
--- /dev/null
+-- 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;