Odyssey
2019030600_check_number_to_fifteen.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 /*
10  * Expanding checknumber column to 15 characters
11  */
12 class CheckNumberToFifteen extends AbstractMigration {
13  public function up() {
14 
15  $cuList = $this->fetchAll('SELECT cu FROM cuadmin');
16  foreach ($cuList as $cuListItem) {
17  $cu = strtolower(trim($cuListItem['cu']));
18  $accountHistoryTableName = "{$cu}accounthistory";
19  if ($this->hasTable($accountHistoryTableName)) {
20  $accountHistoryTable = $this->table($accountHistoryTableName);
21  $accountHistoryTable->changeColumn('checknumber', 'string', ['null' => true, 'limit' => 15])->save();
22  }
23  }
24 
25  if ($this->hasTable('cutronah')) {
26  $cutronahTable = $this->table('cutronah');
27  $cutronahTable->changeColumn('checknumber', 'string', ['null' => true, 'limit' => 15])->save();
28  }
29  }
30 
31  public function down() {
32  }
33 }