From 59460772e3f5cab6933a4c6a14220eeff3bb2c40 Mon Sep 17 00:00:00 2001 From: scottmk Date: Wed, 2 Dec 2009 04:37:32 +0000 Subject: [PATCH] Add two new tables to the query schema: case_branch and from_relation. Also: create a foreign key in stored_query pointing to from_relation. M Open-ILS/src/sql/Pg/002.schema.config.sql A Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql M Open-ILS/examples/fm_IDL.xml git-svn-id: svn://svn.open-ils.org/ILS/trunk@15052 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 43 +++++++++++++++- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- .../sql/Pg/upgrade/0100.schema.query-case-from.sql | 58 ++++++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 5266f754ca..cb8c04270a 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -5422,7 +5422,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + @@ -5450,6 +5450,47 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 11f32a2e01..3cf3cbc205 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0099'); -- Scott McKellar +INSERT INTO config.upgrade_log (version) VALUES ('0100'); -- Scott McKellar CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql b/Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql new file mode 100644 index 0000000000..86ed962380 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql @@ -0,0 +1,58 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0100'); -- Scott McKellar + +CREATE TABLE query.case_branch ( + id SERIAL PRIMARY KEY, + parent_expr INT NOT NULL REFERENCES query.expression + ON DELETE CASCADE + DEFERRABLE INITIALLY DEFERRED, + seq_no INT NOT NULL, + condition INT REFERENCES query.expression + DEFERRABLE INITIALLY DEFERRED, + result INT NOT NULL REFERENCES query.expression + DEFERRABLE INITIALLY DEFERRED, + CONSTRAINT case_branch_parent_seq UNIQUE (parent_expr, seq_no) +); + +CREATE TABLE query.from_relation ( + id SERIAL PRIMARY KEY, + type TEXT NOT NULL CONSTRAINT relation_type CHECK ( + type IN ( 'RELATION', 'SUBQUERY', 'FUNCTION' ) ), + table_name TEXT, + class_name TEXT, + subquery INT REFERENCES query.stored_query, + function_call INT REFERENCES query.expression, + table_alias TEXT NOT NULL, + parent_relation INT REFERENCES query.from_relation + ON DELETE CASCADE + DEFERRABLE INITIALLY DEFERRED, + seq_no INT NOT NULL DEFAULT 1, + join_type TEXT CONSTRAINT good_join_type CHECK ( + join_type IS NULL OR join_type IN + ( 'INNER', 'LEFT', 'RIGHT', 'FULL' ) + ), + on_clause INT REFERENCES query.expression + DEFERRABLE INITIALLY DEFERRED, + CONSTRAINT join_or_core CHECK ( + ( parent_relation IS NULL AND join_type IS NULL + AND on_clause IS NULL and table_alias IS NULL ) + OR + ( parent_relation IS NOT NULL AND join_type IS NOT NULL + AND on_clause IS NOT NULL ) + ) +); + +CREATE UNIQUE INDEX from_parent_seq + ON query.from_relation( parent_relation, seq_no ) + WHERE parent_relation IS NOT NULL; + +-- The following foreign key had to be deferred until +-- query.from_relation existed + +ALTER TABLE query.stored_query + ADD FOREIGN KEY (from_clause) + REFERENCES query.from_relation + DEFERRABLE INITIALLY DEFERRED; + +COMMIT; -- 2.11.0