Stamping upgrade for LP898248: Address Alert
authorThomas Berezansky <tsbere@mvlc.org>
Wed, 14 Dec 2011 15:34:19 +0000 (10:34 -0500)
committerThomas Berezansky <tsbere@mvlc.org>
Wed, 14 Dec 2011 15:38:05 +0000 (10:38 -0500)
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/0657.schema.address-alert.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.address-alert.sql [deleted file]

index ac1f113..15a1cae 100644 (file)
@@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0656', :eg_version); -- dbs/berick
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0657', :eg_version); -- berick/tsbere
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0657.schema.address-alert.sql b/Open-ILS/src/sql/Pg/upgrade/0657.schema.address-alert.sql
new file mode 100644 (file)
index 0000000..d2dbb33
--- /dev/null
@@ -0,0 +1,79 @@
+-- Evergreen DB patch 0657.schema.address-alert.sql
+--
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('0657', :eg_version);
+
+CREATE TABLE actor.address_alert (
+    id              SERIAL  PRIMARY KEY,
+    owner           INT     NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
+    active          BOOL    NOT NULL DEFAULT TRUE,
+    match_all       BOOL    NOT NULL DEFAULT TRUE,
+    alert_message   TEXT    NOT NULL,
+    street1         TEXT,
+    street2         TEXT,
+    city            TEXT,
+    county          TEXT,
+    state           TEXT,
+    country         TEXT,
+    post_code       TEXT,
+    mailing_address BOOL    NOT NULL DEFAULT FALSE,
+    billing_address BOOL    NOT NULL DEFAULT FALSE
+);
+
+CREATE OR REPLACE FUNCTION actor.address_alert_matches (
+        org_unit INT, 
+        street1 TEXT, 
+        street2 TEXT, 
+        city TEXT, 
+        county TEXT, 
+        state TEXT, 
+        country TEXT, 
+        post_code TEXT,
+        mailing_address BOOL DEFAULT FALSE,
+        billing_address BOOL DEFAULT FALSE
+    ) RETURNS SETOF actor.address_alert AS $$
+
+SELECT *
+FROM actor.address_alert
+WHERE
+    active
+    AND owner IN (SELECT id FROM actor.org_unit_ancestors($1)) 
+    AND (
+        (NOT mailing_address AND NOT billing_address)
+        OR (mailing_address AND $9)
+        OR (billing_address AND $10)
+    )
+    AND (
+            (
+                match_all
+                AND COALESCE($2, '') ~* COALESCE(street1,   '.*')
+                AND COALESCE($3, '') ~* COALESCE(street2,   '.*')
+                AND COALESCE($4, '') ~* COALESCE(city,      '.*')
+                AND COALESCE($5, '') ~* COALESCE(county,    '.*')
+                AND COALESCE($6, '') ~* COALESCE(state,     '.*')
+                AND COALESCE($7, '') ~* COALESCE(country,   '.*')
+                AND COALESCE($8, '') ~* COALESCE(post_code, '.*')
+            ) OR (
+                NOT match_all 
+                AND (  
+                       $2 ~* street1
+                    OR $3 ~* street2
+                    OR $4 ~* city
+                    OR $5 ~* county
+                    OR $6 ~* state
+                    OR $7 ~* country
+                    OR $8 ~* post_code
+                )
+            )
+        )
+    ORDER BY actor.org_unit_proximity(owner, $1)
+$$ LANGUAGE SQL;
+
+COMMIT;
+
+/* UNDO
+DROP FUNCTION actor.address_alert_matches(INT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, BOOL, BOOL);
+DROP TABLE actor.address_alert;
+*/
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.address-alert.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.address-alert.sql
deleted file mode 100644 (file)
index aed3dce..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
--- Evergreen DB patch XXXX.schema.address-alert.sql
---
-BEGIN;
-
--- check whether patch can be applied
-SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
-
-CREATE TABLE actor.address_alert (
-    id              SERIAL  PRIMARY KEY,
-    owner           INT     NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
-    active          BOOL    NOT NULL DEFAULT TRUE,
-    match_all       BOOL    NOT NULL DEFAULT TRUE,
-    alert_message   TEXT    NOT NULL,
-    street1         TEXT,
-    street2         TEXT,
-    city            TEXT,
-    county          TEXT,
-    state           TEXT,
-    country         TEXT,
-    post_code       TEXT,
-    mailing_address BOOL    NOT NULL DEFAULT FALSE,
-    billing_address BOOL    NOT NULL DEFAULT FALSE
-);
-
-CREATE OR REPLACE FUNCTION actor.address_alert_matches (
-        org_unit INT, 
-        street1 TEXT, 
-        street2 TEXT, 
-        city TEXT, 
-        county TEXT, 
-        state TEXT, 
-        country TEXT, 
-        post_code TEXT,
-        mailing_address BOOL DEFAULT FALSE,
-        billing_address BOOL DEFAULT FALSE
-    ) RETURNS SETOF actor.address_alert AS $$
-
-SELECT *
-FROM actor.address_alert
-WHERE
-    active
-    AND owner IN (SELECT id FROM actor.org_unit_ancestors($1)) 
-    AND (
-        (NOT mailing_address AND NOT billing_address)
-        OR (mailing_address AND $9)
-        OR (billing_address AND $10)
-    )
-    AND (
-            (
-                match_all
-                AND COALESCE($2, '') ~* COALESCE(street1,   '.*')
-                AND COALESCE($3, '') ~* COALESCE(street2,   '.*')
-                AND COALESCE($4, '') ~* COALESCE(city,      '.*')
-                AND COALESCE($5, '') ~* COALESCE(county,    '.*')
-                AND COALESCE($6, '') ~* COALESCE(state,     '.*')
-                AND COALESCE($7, '') ~* COALESCE(country,   '.*')
-                AND COALESCE($8, '') ~* COALESCE(post_code, '.*')
-            ) OR (
-                NOT match_all 
-                AND (  
-                       $2 ~* street1
-                    OR $3 ~* street2
-                    OR $4 ~* city
-                    OR $5 ~* county
-                    OR $6 ~* state
-                    OR $7 ~* country
-                    OR $8 ~* post_code
-                )
-            )
-        )
-    ORDER BY actor.org_unit_proximity(owner, $1)
-$$ LANGUAGE SQL;
-
-COMMIT;
-
-/* UNDO
-DROP FUNCTION actor.address_alert_matches(INT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, BOOL, BOOL);
-DROP TABLE actor.address_alert;
-*/