Odyssey
2017110700_admeco.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 Admeco extends AbstractMigration {
10 
11  /* This is the process for moving forward. We are re-creating the table so if there is
12  * existing data will need to create a temporary table, copy the data, drop the old table,
13  * rename the temporary table.
14  */
15  public function up() {
16  // check if we already made the change
17  $table = $this->table("cuadmeco");
18  $hasColumn = $table->hasColumn('accountnumber');
19 
20  if ($hasColumn)
21  {
22  print "Removing accountnumber column.\n";
23  $this->query("alter table cuadmeco drop column accountnumber");
24  }
25 
26  }
27 
28  /* To execute this you need to run the following command:
29  * php vendor/bin/phinx rollback (using correct path to phinx)
30  * Or, to roll back to a specific time:
31  * php vendor/bin/phinx rollback -t 20151123211207
32  */
33  public function down() {
34  // check if we already made the change
35  $table = $this->table("cuadmeco");
36  $hasColumn = $table->hasColumn('accountnumber');
37 
38  if (!$hasColumn)
39  {
40  print "Adding accountnumber column.\n";
41  $this->query("alter table cuadmeco add column accountnumber character(12) not null");
42  }
43  }
44 }
45 
46 ?>