Odyssey
2017101600_removestale.php
1 <?php
2 /* Notes:
3  * 1. Anything complicated needs to be done with SQL.
4  * 2. Always have a check to know if the migration needs to occur (up or down).
5  * 3. Use up() and down(), not change(), because of the SQL
6  */
7 use Phinx\Migration\AbstractMigration;
8 
9 class RemoveStale extends AbstractMigration {
10 
11  /*
12  * remove the column "stale" from account and loan balance tables
13  */
14  public function up() {
15 
16  $cuList = $this->fetchAll('SELECT cu FROM cuadmin');
17  for ($i = 0; $i < count($cuList); $i ++) {
18  $cu = strtolower( trim( $cuList[$i]["cu"] ) );
19  $tableAcct = $this->hasTable("{$cu}accountbalance");
20  $tableLoan = $this->hasTable("{$cu}loanbalance");
21 
22  if ($tableAcct) {
23  $sql = "ALTER TABLE {$cu}accountbalance DROP COLUMN stale";
24  $this->query($sql);
25  }
26 
27  if ($tableLoan) {
28  $sql = "ALTER TABLE {$cu}loanbalance DROP COLUMN stale";
29  $this->query($sql);
30  }
31  }
32  }
33 
34  /* To execute this you need to run the following command:
35  * php vendor/bin/phinx rollback (using correct path to phinx)
36  * Or, to roll back to a specific time:
37  * php vendor/bin/phinx rollback -t 20151123211207
38  */
39  public function down() {
40 
41  }
42 }
43 
44 ?>