Odyssey
2018100200_ExtendCutronAHCheckNum.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 ExtendCutronAHCheckNum extends AbstractMigration {
11  public function up() {
12  $tableName = "cutronah";
13  $tableColumn = "checknumber";
14 
15  if ($this->hasTable($tableName)) {
16  $table = $this->table( $tableName );
17 
18  $hasColumn = $table->hasColumn( $tableColumn );
19 
20  if ( $hasColumn ) {
21  print "Upgrade {$tableName}.\n";
22 
23  // Alter column
24  $this->query("alter table $tableName alter column $tableColumn type char(9)");
25  }
26  } else {
27  print "Skip $tableName, table not found.\n";
28  }
29  } // End "up" function.
30 
31  public function down() {
32  $tableName = "cutronah";
33  $tableColumn = "checknumber";
34 
35  if ($this->hasTable($tableName)) {
36  $table = $this->table( $tableName );
37 
38  $hasColumn = $table->hasColumn( $tableColumn );
39 
40  if ( $hasColumn ) {
41  print "Not downgrading {$tableName}.\n";
42 
43  // Alter column
44 // $this->query("alter table $tableName alter column $tableColumn type char(6)");
45  }
46  } else {
47  print "Skip $tableName, table not found.\n";
48  }
49  } // End "down" function
50 }