]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0607.schema.oua_force_order.sql
master-stamped upgrade script for LP#816131
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0607.schema.oua_force_order.sql
1 -- Evergreen DB patch 0607.schema.oua_force_order.sql
2 --
3 --
4 BEGIN;
5
6
7 -- check whether patch can be applied
8 SELECT evergreen.upgrade_deps_block_check('0607', :eg_version);
9
10 CREATE OR REPLACE FUNCTION actor.org_unit_ancestors( INT ) RETURNS SETOF actor.org_unit AS $$
11     WITH RECURSIVE org_unit_ancestors_distance(id, distance) AS (
12             SELECT $1, 0
13         UNION
14             SELECT ou.parent_ou, ouad.distance+1
15             FROM actor.org_unit ou JOIN org_unit_ancestors_distance ouad ON (ou.id = ouad.id)
16             WHERE ou.parent_ou IS NOT NULL
17     )
18     SELECT ou.* FROM actor.org_unit ou JOIN org_unit_ancestors_distance ouad USING (id) ORDER BY ouad.distance DESC;
19 $$ LANGUAGE SQL ROWS 1;
20
21
22
23 COMMIT;