Odyssey
2018040300_lnappUser.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 LnappUser extends AbstractMigration {
10 
11  /*
12  * Drop the 'user_name' column from the lnappuser table.
13  * This process assumes an empty table and will not make any data changes
14  */
15  public function up() {
16 
17  // Reference lnappuser table
18  $tableName = "lnappuser";
19  $table = $this->table( $tableName );
20 
21  // Evaluate if tables has the column 'user_name'
22  $hasColumn = $table->hasColumn('user_name');
23 
24  // IF the column exists then we will be:
25  // dropping the column
26  // adding the column banking_user_id
27  if ( $hasColumn ) {
28  // announce it
29  print "Migration - Upgrade $cu {$tableName}\n";
30 
31  /*
32  * DROP COLUMN (user_name)
33  */
34 
35  $table->removeColumn('user_name')
36  ->save();
37 
38  /*
39  * ADD COLUMN (banking_user_id)
40  */
41  $table->addColumn('banking_user_id', 'integer', array('null' => true))
42  ->save();
43  }
44  }
45 }