Add updatable view query.expr_string.
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Dec 2009 16:23:34 +0000 (16:23 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Dec 2009 16:23:34 +0000 (16:23 +0000)
Change a datatype in query.record_column.

M    Open-ILS/src/sql/Pg/002.schema.config.sql
M    Open-ILS/src/sql/Pg/008.schema.query.sql
A    Open-ILS/src/sql/Pg/upgrade/0104.schema.query-expr-string.sql
M    Open-ILS/examples/fm_IDL.xml

git-svn-id: svn://svn.open-ils.org/ILS/trunk@15070 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/008.schema.query.sql
Open-ILS/src/sql/Pg/upgrade/0104.schema.query-expr-string.sql [new file with mode: 0644]

index 37352b2..4de8c7f 100644 (file)
@@ -5554,6 +5554,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </permacrud>
        </class>
 
+       <class id="xstr" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_string" oils_persist:tablename="query.expr_string" reporter:label="String Expression">
+               <fields oils_persist:primary="id" oils_persist:sequence="expression_id_seq">
+                       <field reporter:label="Expression ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Is Parenthesized" name="parenthesize" reporter:datatype="bool"/>
+                       <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="Literal" name="literal" reporter:datatype="text"/>
+               </fields>
+               <links>
+                       <link field="parent_expr" 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. -->
        <!-- ********************************************************************************************************************* -->
index 7a8af5e..9975722 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 ('0103'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0104'); -- Scott McKellar
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index f94db2b..0389479 100644 (file)
@@ -229,7 +229,9 @@ CREATE TABLE query.record_column (
                                        DEFERRABLE INITIALLY DEFERRED,
        seq_no        INT               NOT NULL,
        column_name   TEXT              NOT NULL,
-       column_type   TEXT              NOT NULL,
+    column_type   INT               NOT NULL REFERENCES query.datatype
+                                    ON DELETE CASCADE
+                                    DEFERRABLE INITIALLY DEFERRED,
        CONSTRAINT column_sequence UNIQUE (from_relation, seq_no)
 );
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/0104.schema.query-expr-string.sql b/Open-ILS/src/sql/Pg/upgrade/0104.schema.query-expr-string.sql
new file mode 100644 (file)
index 0000000..c0125a3
--- /dev/null
@@ -0,0 +1,55 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0104'); -- Scott McKellar
+
+-- Create updatable view
+
+CREATE OR REPLACE VIEW query.expr_string AS
+    SELECT
+        id,
+        parenthesize,
+        parent_expr,
+        seq_no,
+        literal
+    FROM
+        query.expression
+    WHERE
+        type = 'xstr';
+
+CREATE OR REPLACE RULE query_expr_string_insert_rule AS
+    ON INSERT TO query.expr_string
+    DO INSTEAD
+    INSERT INTO query.expression (
+        id,
+        type,
+        parenthesize,
+        parent_expr,
+        seq_no,
+        literal
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xstr',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+        NEW.literal
+    );
+
+CREATE OR REPLACE RULE query_expr_string_update_rule AS
+    ON UPDATE TO query.expr_string
+    DO INSTEAD
+    UPDATE query.expression SET
+        id = NEW.id,
+        parenthesize = NEW.parenthesize,
+        parent_expr = NEW.parent_expr,
+        seq_no = NEW.seq_no,
+        literal = NEW.literal
+    WHERE
+        id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_string_delete_rule AS
+    ON DELETE TO query.expr_string
+    DO INSTEAD
+    DELETE FROM query.expression WHERE id = OLD.id;
+
+COMMIT;