Odyssey
2019072501_increaseTracenumber.php
1 <?php
2 /**
3  * Notes:
4  * 1. Anything complicated needs to be done with SQL.
5  * 2. Always have a check to know if the migration needs to occur (up or down).
6  * 3. Use up() and down(), not change(), because of the SQL
7  */
8 use Phinx\Migration\AbstractMigration;
9 
10 class IncreaseTracenumber extends AbstractMigration {
11  public function up() {
12  /*
13  * Updating ext_withdraw
14  */
15  $cuList = $this->fetchAll('select cu from cuadmin');
16  $cuTableList = array(
17  array("table" => "accounthistory", "column" => "tracenumber"),
18  array("table" => "loanhistory", "column" => "tracenumber")
19  );
20  $globalTableList = array(
21  array("table" => "cutronah", "column" => "tracenumber"),
22  array("table" => "cutronlh", "column" => "tracenumber"),
23  array("table" => "cu_alerts", "column" => "lasttrace")
24  );
25  $size = 22;
26  foreach ($cuList as $cuListItem) {
27  $cu = strtolower(trim($cuListItem['cu']));
28 
29  foreach($cuTableList as $cuTableRecord) {
30  $table = $cu . $cuTableRecord["table"];
31  $column = $cuTableRecord["column"];
32  if ($this->hasTable($table)) {
33  print "Updating table $table...\n";
34  $sql = "alter table $table alter column $column type character($size)";
35  $this->query($sql);
36  }
37  }
38  }
39 
40  foreach($globalTableList as $tableRecord) {
41  $table = $tableRecord["table"];
42  $column = $tableRecord["column"];
43  if ($this->hasTable($table)) {
44  print "Updating table $table...\n";
45  $sql = "alter table $table alter column $column type character($size)";
46  $this->query($sql);
47  }
48  }
49  }
50 
51  public function down() {
52 
53  }
54 }