FOSSology  4.4.0
Open Source License Compliance by Open Source Software
dbmigrate_2.0-2.5-pre.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
23 function Migrate_20_25($Verbose)
24 {
25  global $PG_CONN;
26 
27  $sql = "select count(*) from pg_class where relname='copyright';";
28  $result = pg_query($PG_CONN, $sql);
29  DBCheckResult($result, $sql, __FILE__, __LINE__);
30  $row = pg_fetch_assoc($result);
31  pg_free_result($result);
32  if (1 > $row['count']) {
33  return 0; // fresh install, even no copyright table
34  }
35 
36  $sql = "delete from copyright where pfile_fk not in (select pfile_pk from pfile);";
37  $result = pg_query($PG_CONN, $sql);
38  DBCheckResult($result, $sql, __FILE__, __LINE__);
39  pg_free_result($result);
40 
42  $sql = "SELECT conname from pg_constraint where conname= 'copyright_pfile_fk_fkey';";
43  $conresult = pg_query($PG_CONN, $sql);
44  DBCheckResult($conresult, $sql, __FILE__, __LINE__);
45  if (pg_num_rows($conresult) == 0) {
46  $sql = "ALTER TABLE copyright ADD CONSTRAINT copyright_pfile_fk_fkey FOREIGN KEY (pfile_fk) REFERENCES pfile (pfile_pk) ON DELETE CASCADE; ";
47  $result = pg_query($PG_CONN, $sql);
48  DBCheckResult($result, $sql, __FILE__, __LINE__);
49  pg_free_result($result);
50  print "add contr\n";
51  }
52  pg_free_result($conresult);
53  return 0;
54 } // Migrate_20_25()
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
Migrate_20_25($Verbose)
Delete from copyright where pfile_fk not in (select pfile_pk from pfile) add foreign constraint on co...
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN