38   $sql = 
"SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_inherits WHERE inhrelid = 'public.uploadtree_a'::regclass::oid);";
    39   $row = 
RunSQL($sql, $DryRun);
    41   foreach ($row as $exist_key => $exist_value) {
    44   if (@$exist_value == 
't') 
    47       echo __FUNCTION__.
": Data previously migrated.\n";
    53   $sql = 
"select uploadtree_pk from uploadtree limit 1";
    54   $row = 
RunSQL($sql, $DryRun);
    57     echo 
"Migrating existing uploadtree data.\n";
    60     $sql = 
"drop table uploadtree_a";
    64     $sql = 
"alter table uploadtree rename to uploadtree_a";
    68     $sql = 
"create table uploadtree (like uploadtree_a INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES)";
    72     $sql = 
"alter table uploadtree add foreign key (upload_fk) references upload(upload_pk) on delete cascade";
    77   $sql = 
"SELECT conname from pg_constraint where conname= 'uploadtree_a_upload_fk_fkey';";
    78   $row = 
RunSQL($sql, $DryRun);
    80     $sql = 
"alter table uploadtree_a add foreign key (upload_fk) references upload(upload_pk) on delete cascade";
    85   $sql = 
"update upload set uploadtree_tablename='uploadtree_a' where uploadtree_tablename is null";
    89   $sql = 
"alter table uploadtree_a inherit uploadtree";
   109     echo 
"DryRun: $sql\n";
   112     $result = pg_query($PG_CONN, $sql);
   114     $row = pg_fetch_assoc($result);
   115     pg_free_result($result);
 RunSQL($sql, $DryRun)
Run a SQL query and return the result array. 
 
Migrate_20_21($DryRun)
Migrate to the uploadtree_a table. 
 
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
 
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.