← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8980: Script

 

------------------------------------------------------------
revno: 8980
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-11-12 19:23:15 +0100
message:
  Script
modified:
  resources/sql/div.sql


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'resources/sql/div.sql'
--- resources/sql/div.sql	2012-11-07 08:12:06 +0000
+++ resources/sql/div.sql	2012-11-12 18:23:15 +0000
@@ -102,3 +102,17 @@
 (select count(*) from reporttable_orgunitgroups where reporttableid=rt.reporttableid) as oug,
 (select count(*) from reporttable_periods where reporttableid=rt.reporttableid) as pe
 from reporttable rt;
+
+-- Insert random org unit codes
+
+create function setrandomcode() returns integer AS $$
+declare ou integer;
+begin
+for ou in select organisationunitid from _orgunitstructure where level=6 loop
+  execute 'update organisationunit set code=(select substring(cast(random() as text),5,6)) where organisationunitid=' || ou;
+end loop;
+return 1;
+end;
+$$ language plpgsql;
+
+select setrandomcode();