Odyssey
2018100901_extendVendorCacheUsername.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 class ExtendVendorCacheUsername extends AbstractMigration {
10  public function up() {
11  $tableName = "cu_vendorcache";
12  $tableColumn = "username";
13  if ($this->hasTable($tableName)) {
14  $table = $this->table( $tableName );
15  $hasColumn = $table->hasColumn( $tableColumn );
16  if ( $hasColumn ) {
17  print "Upgrade {$tableName}.\n";
18  // Alter column
19  $this->query("alter table $tableName alter column $tableColumn type varchar(50)");
20  }
21  } else {
22  print "Skip $tableName, table not found.\n";
23  }
24  } // End "up" function.
25 
26  public function down() {
27  $tableName = "cu_vendorcache";
28  $tableColumn = "username";
29  if ($this->hasTable($tableName)) {
30  $table = $this->table( $tableName );
31  $hasColumn = $table->hasColumn( $tableColumn );
32  if ( $hasColumn ) {
33  print "Downgrade {$tableName}.\n";
34  // Alter column
35  $this->query("alter table $tableName alter column $tableColumn type char(12)");
36  }
37  } else {
38  print "Skip $tableName, table not found.\n";
39  }
40  } // End "down" function
41 }