Odyssey
2019052000_addFeatureGate.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 
10 class AddFeaturegate extends AbstractMigration {
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  // create cucorerequests table if it doesn't exist
19  $exists = $this->hasTable("cufeaturegate");
20 
21  if (!$exists) {
22  $sql = "
23  CREATE TABLE cufeaturegate (
24  feature character varying(10) NOT NULL,
25  description character varying(255),
26  enabled_all character(1),
27  enabled_cu character varying
28  );";
29  $sqlRs = $this->query($sql);
30 
31  // add comments for table and columns
32  $sql = "COMMENT ON TABLE cufeaturegate IS 'Table to help the gating of features into master.';";
33  $sqlRs = $this->query($sql);
34 
35  $sql = "COMMENT ON COLUMN cufeaturegate.feature IS 'A developer created Feature Code to identify feature being gated.';";
36  $sqlRs = $this->query($sql);
37 
38  $sql = "COMMENT ON COLUMN cufeaturegate.description IS 'More verbose description to help other understand the feature.';";
39  $sqlRs = $this->query($sql);
40 
41  $sql = "COMMENT ON COLUMN cufeaturegate.enabled_all IS 'Global feature setting. {Y}-Enabled All, {N}-Not enabled, {O}-Off for everyone.';";
42  $sqlRs = $this->query($sql);
43 
44  $sql = "COMMENT ON COLUMN cufeaturegate.enabled_cu IS 'Enabled list for credit unions.';";
45  $sqlRs = $this->query($sql);
46 
47  // set primary key constraint on feature column
48  $sql = "ALTER TABLE ONLY cufeaturegate ADD CONSTRAINT pk_cufeaturegate_feature PRIMARY KEY (feature);";
49  $sqlRs = $this->query($sql);
50 
51  }
52  }
53 
54  /* To execute this you need to run the following command:
55  * php vendor/bin/phinx rollback (using correct path to phinx)
56  * Or, to roll back to a specific time:
57  * php vendor/bin/phinx rollback -t 20151123211207
58  */
59  public function down() {
60  // drop cucorerequests table
61  $this->dropTable("cufeaturegate");
62  }
63 }
64 
65 ?>