[open-ils-commits] r15052 - in trunk/Open-ILS: examples src/sql/Pg src/sql/Pg/upgrade (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Dec 1 23:37:35 EST 2009
Author: scottmk
Date: 2009-12-01 23:37:32 -0500 (Tue, 01 Dec 2009)
New Revision: 15052
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql
Modified:
trunk/Open-ILS/examples/fm_IDL.xml
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
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
Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml 2009-12-02 01:23:16 UTC (rev 15051)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2009-12-02 04:37:32 UTC (rev 15052)
@@ -5422,7 +5422,7 @@
</class>
<class id="qxp" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expression" oils_persist:tablename="query.expression" reporter:label="Expression">
- <fields oils_persist:primary="id" oils_persist:sequence="">
+ <fields oils_persist:primary="id" oils_persist:sequence="expression_id_seq">
<field reporter:label="Expression ID" name="id" reporter:datatype="id"/>
<field reporter:label="Expression Type" name="type" reporter:datatype="text"/>
<field reporter:label="Is Parenthesized" name="parenthesize" reporter:datatype="bool"/>
@@ -5450,6 +5450,47 @@
</permacrud>
</class>
+ <class id="qcb" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::case_branch" oils_persist:tablename="query.case_branch" reporter:label="Case Branch">
+ <fields oils_persist:primary="id" oils_persist:sequence="case_branch_id_seq">
+ <field reporter:label="Case Branch ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="Parent Expression" name="parent_expr" reporter:datatype="link"/>
+ <field reporter:label="Sequence Number" name="seq_no" reporter:datatype="int"/>
+ <field reporter:label="Condition" name="condition" reporter:datatype="link"/>
+ <field reporter:label="Result" name="result" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+ <link field="condition" reltype="might_have" key="id" map="" class="qxp"/>
+ <link field="result" reltype="has_a" key="id" map="" class="qxp"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
+ <class id="qfr" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::from_relation" oils_persist:tablename="query.from_relation" reporter:label="From Relation">
+ <fields oils_persist:primary="id" oils_persist:sequence="from_relation_id_seq">
+ <field reporter:label="From Relation ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="From Relation Type" name="type" reporter:datatype="text"/>
+ <field reporter:label="Table Name" name="table_name" reporter:datatype="text"/>
+ <field reporter:label="Class Name" name="class_name" reporter:datatype="text"/>
+ <field reporter:label="Subquery ID" name="subquery" reporter:datatype="link"/>
+ <field reporter:label="Function Call ID" name="function_call" reporter:datatype="link"/>
+ <field reporter:label="Table Alias" name="table_alias" reporter:datatype="text"/>
+ <field reporter:label="Parent Relation ID" name="parent_relation" reporter:datatype="link"/>
+ <field reporter:label="Sequence Number" name="seq_no" reporter:datatype="int"/>
+ <field reporter:label="Join Type" name="join_type" reporter:datatype="text"/>
+ <field reporter:label="On Clause ID" name="on_clause" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="subquery" reltype="might_have" key="id" map="" class="qsq"/>
+ <link field="function_call" reltype="might_have" key="id" map="" class="qxp"/>
+ <link field="parent_relation" reltype="might_have" key="id" map="" class="qfr"/>
+ <link field="on_clause" reltype="might_have" key="id" map="" class="qxp"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
<!-- ********************************************************************************************************************* -->
<!-- What follows is a set of example extensions that are useful for PINES. Comment out or remove if you don't want them. -->
<!-- ********************************************************************************************************************* -->
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-12-02 01:23:16 UTC (rev 15051)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-12-02 04:37:32 UTC (rev 15052)
@@ -51,7 +51,7 @@
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,
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0100.schema.query-case-from.sql 2009-12-02 04:37:32 UTC (rev 15052)
@@ -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;
More information about the open-ils-commits
mailing list