Odyssey
2017091500_tron2.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 Tron2 extends AbstractMigration
10 {
11 
12  /* This is the process for moving forward. We are re-creating the table so if there is
13  * existing data will need to create a temporary table, copy the data, drop the old table,
14  * rename the temporary table.
15  */
16  public function up()
17  {
18  $name = "cutronus";
19  $tableExists = $this->hasTable( $name );
20 
21  // drop it if it exists
22  if ( $tableExists ) {
23  $sql = "DROP TABLE cutronus";
24  $rows = $this->query( $sql );
25 
26  $tableExists = false;
27  }
28 
29  if ( !$tableExists ) {
30  // announce it
31  print "Creating table $name\n";
32 
33  // create the SQL for the new table
34  // note: sched_id is used for background scheduled transactions; accountnumber is used for background alerts
35  $sql = "CREATE TABLE cutronus (
36  runslot character varying(10) NOT NULL,
37  cu character(10),
38  user_id integer NOT NULL,
39  shuffle double precision,
40  sched_id integer NOT NULL,
41  accountnumber character(12) NOT NULL,
42  PRIMARY KEY (runslot, cu, user_id, sched_id, accountnumber)
43  )";
44 
45  // create the table
46  $rows = $this->query( $sql );
47  }
48  }
49 
50  /* To execute this you need to run the following command:
51  * php vendor/bin/phinx rollback (using correct path to phinx)
52  * Or, to roll back to a specific time:
53  * php vendor/bin/phinx rollback -t 20151123211207
54  */
55  public function down()
56  {
57  // an earlier migration file will drop all the tables
58  }
59 }