FOSSology  4.4.0
Open Source License Compliance by Open Source Software
dbmigrate_multiple_copyright_decisions.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2017 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
17 function addBooleanColumnTo($dbManager, $tableName, $columnName = 'is_enabled')
18 {
19  echo "Migrate: Add and setup column=$columnName to table=$tableName\n";
20  if (! $dbManager->existsColumn($tableName, $columnName))
21  {
22  $dbManager->queryOnce("ALTER TABLE $tableName
23  ADD COLUMN $columnName BOOLEAN;");
24  }
25 
26  $dbManager->queryOnce("UPDATE $tableName
27  SET $columnName = " . $tableName . "_pk IN
28  (SELECT MAX(" . $tableName . "_pk) AS enabled_pk
29  FROM $tableName
30  GROUP BY pfile_fk);");
31  $dbManager->queryOnce("ALTER TABLE $tableName
32  ALTER COLUMN $columnName
33  SET NOT NULL;");
34  $dbManager->queryOnce("ALTER TABLE $tableName
35  ALTER COLUMN $columnName
36  SET DEFAULT TRUE;");
37 }
38 
39 foreach (array('copyright','ecc') as $name)
40 {
41  /* @var $dbManager DbManager */
42  addBooleanColumnTo($dbManager, $name.'_decision');
43 }