Odyssey
2017080400_calendar.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 Calendar 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 
17  // create scheduledtxn table if it doesn't exist
18  $exists = $this->hasTable("cu_calendar");
19 
20  if (!$exists) {
21  $sql = "
22  CREATE TABLE cu_calendar (
23  cu character varying(10) NOT NULL,
24  year character varying(4) NOT NULL,
25  dates text NOT NULL
26  );";
27  $sqlRs = $this->query($sql);
28 
29  // create sequence
30  $sql = "ALTER TABLE ONLY cu_calendar ADD CONSTRAINT cu_calendar_pkey PRIMARY KEY (cu, year);";
31  $sqlRs = $this->query($sql);
32  }
33  }
34 
35  /* To execute this you need to run the following command:
36  * php vendor/bin/phinx rollback (using correct path to phinx)
37  * Or, to roll back to a specific time:
38  * php vendor/bin/phinx rollback -t 20151123211207
39  */
40  public function down() {
41  // drop cu_scheduledtxn table
42  $this->dropTable("cu_calendar");
43  }
44 }
45 
46 ?>