Add two tables to the sql schema: stored_query and query_sequence.
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 30 Nov 2009 19:58:13 +0000 (19:58 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 30 Nov 2009 19:58:13 +0000 (19:58 +0000)
M    Open-ILS/src/sql/Pg/002.schema.config.sql
A    Open-ILS/src/sql/Pg/upgrade/0098.schema.sql-stored-query.sql
M    Open-ILS/examples/fm_IDL.xml

git-svn-id: svn://svn.open-ils.org/ILS/trunk@15045 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/0098.schema.sql-stored-query.sql [new file with mode: 0644]

index 2d53ec3..950dd78 100644 (file)
@@ -5333,6 +5333,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </links>
     </class>
 
+       <class id="qsq" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="sql::stored_query" oils_persist:tablename="sql.stored_query" reporter:label="Stored Query">
+               <fields oils_persist:primary="id" oils_persist:sequence="sql.stored_query_id_seq">
+                       <field reporter:label="Query ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Query type" name="type" reporter:datatype="text"/>
+                       <field reporter:label="Use ALL" name="use_all" reporter:datatype="bool"/>
+                       <field reporter:label="Use DISTINCT" name="use_distinct" reporter:datatype="bool"/>
+                       <field reporter:label="FROM Clause" name="from_clause" reporter:datatype="int"/>
+                       <field reporter:label="WHERE Clause" name="where_clause" reporter:datatype="int"/>
+                       <field reporter:label="HAVING Clause" name="having_clause" reporter:datatype="int"/>
+               </fields>
+               <links>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+               </permacrud>
+       </class>
+
+       <class id="qseq" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="sql::query_sequence" oils_persist:tablename="sql.query_sequence" reporter:label="Query Sequence">
+               <fields oils_persist:primary="id" oils_persist:sequence="sql.sql.query_sequence_id_seq">
+                       <field reporter:label="Query Seq ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Parent Query" name="parent_query" reporter:datatype="link"/>
+                       <field reporter:label="Sequence Number" name="seq_no" reporter:datatype="int"/>
+                       <field reporter:label="Child Query" name="child_query" reporter:datatype="link"/>
+               </fields>
+               <links>
+                       <link field="parent_query" reltype="has_a" key="id" map="" class="qsq"/>
+                       <link field="child_query" reltype="has_a" key="id" map="" class="qsq"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+               </permacrud>
+       </class>
+
        <class id="qdt" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="sql::datatype" oils_persist:tablename="sql.datatype" reporter:label="Datatype">
                <fields oils_persist:primary="id" oils_persist:sequence="sql.datatype_id_seq">
                        <field reporter:label="Datatype ID" name="id" reporter:datatype="id"/>
index e2be7f1..5170d61 100644 (file)
@@ -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 ('0097'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0098'); -- Scott McKellar
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0098.schema.sql-stored-query.sql b/Open-ILS/src/sql/Pg/upgrade/0098.schema.sql-stored-query.sql
new file mode 100644 (file)
index 0000000..1134f31
--- /dev/null
@@ -0,0 +1,34 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0098'); -- Scott McKellar
+
+CREATE TABLE  sql.stored_query (
+       id            SERIAL         PRIMARY KEY,
+       type          TEXT           NOT NULL CONSTRAINT query_type CHECK
+                                    ( type IN ( 'SELECT', 'UNION', 'INTERSECT', 'EXCEPT' ) ),
+       use_all       BOOLEAN        NOT NULL DEFAULT FALSE,
+       use_distinct  BOOLEAN        NOT NULL DEFAULT FALSE,
+       from_clause   INT            NOT NULL , --REFERENCES sql.from_clause
+       where_clause  INT            , --REFERENCES sql.expression
+                                    --DEFERRABLE INITIALLY DEFERRED,
+       having_clause INT            --REFERENCES sql.expression
+                                    --DEFERRABLE INITIALLY DEFERRED
+);
+
+-- (Foreign keys to be defined later after other tables are created)
+
+CREATE TABLE sql.query_sequence (
+       id              SERIAL            PRIMARY KEY,
+       parent_query    INT               NOT NULL
+                                         REFERENCES sql.stored_query
+                                                                         ON DELETE CASCADE
+                                                                         DEFERRABLE INITIALLY DEFERRED,
+       seq_no          INT               NOT NULL,
+       child_query     INT               NOT NULL
+                                         REFERENCES sql.stored_query
+                                                                         ON DELETE CASCADE
+                                                                         DEFERRABLE INITIALLY DEFERRED,
+       CONSTRAINT sql_query_seq UNIQUE( parent_query, seq_no )
+);
+
+COMMIT;