Odyssey
2018121800_addCucorerequests.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 AddCucorerequests 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("cucorerequests");
20 
21  if (!$exists) {
22  $sql = "
23  CREATE TABLE cucorerequests (
24  id integer NOT NULL,
25  cu character(12),
26  appliance_ip character varying(100),
27  accountnumber character(12),
28  request_type character varying(20),
29  request_url character varying,
30  request_start timestamp without time zone,
31  request_end timestamp without time zone,
32  request_elapsed integer,
33  request_status character varying,
34  remote_ip character(15)
35  );";
36  $sqlRs = $this->query($sql);
37 
38  // add comments for table and columns
39  $sql = "COMMENT ON TABLE cucorerequests IS 'Store status info of the requests made to a live credit union core.';";
40  $sqlRs = $this->query($sql);
41 
42  $sql = "COMMENT ON COLUMN cucorerequests.cu IS 'The Credit Union Code.';";
43  $sqlRs = $this->query($sql);
44 
45  $sql = "COMMENT ON COLUMN cucorerequests.appliance_ip IS 'The target appliance ip or dns name.';";
46  $sqlRs = $this->query($sql);
47 
48  $sql = "COMMENT ON COLUMN cucorerequests.accountnumber IS 'Associated member accountnumber.';";
49  $sqlRs = $this->query($sql);
50 
51  $sql = "COMMENT ON COLUMN cucorerequests.request_type IS 'Type of core request made.';";
52  $sqlRs = $this->query($sql);
53 
54  $sql = "COMMENT ON COLUMN cucorerequests.request_url IS 'Request URL to core vendor appliance.';";
55  $sqlRs = $this->query($sql);
56 
57  $sql = "COMMENT ON COLUMN cucorerequests.request_start IS 'Request start timestamp.';";
58  $sqlRs = $this->query($sql);
59 
60  $sql = "COMMENT ON COLUMN cucorerequests.request_end IS 'Request end timestamp.';";
61  $sqlRs = $this->query($sql);
62 
63  $sql = "COMMENT ON COLUMN cucorerequests.request_elapsed IS 'Duration of request in seconds.';";
64  $sqlRs = $this->query($sql);
65 
66  $sql = "COMMENT ON COLUMN cucorerequests.request_status IS 'Status composed as a JSON string.';";
67  $sqlRs = $this->query($sql);
68 
69  $sql = "COMMENT ON COLUMN cucorerequests.remote_ip IS 'Remote IP Address.';";
70  $sqlRs = $this->query($sql);
71 
72  // create sequence
73  $sql = "
74  CREATE SEQUENCE cucorerequests_id_seq
75  START WITH 1
76  INCREMENT BY 1
77  NO MINVALUE
78  NO MAXVALUE
79  CACHE 1;";
80  $sqlRs = $this->query($sql);
81 
82  // set sequence owner
83  $sql = "ALTER SEQUENCE cucorerequests_id_seq OWNED BY cucorerequests.id;";
84  $sqlRs = $this->query($sql);
85 
86  $sql = "ALTER TABLE ONLY cucorerequests ALTER COLUMN id SET DEFAULT nextval('cucorerequests_id_seq'::regclass);";
87  $sqlRs = $this->query($sql);
88 
89  // set primary key constraint on id column
90  $sql = "ALTER TABLE ONLY cucorerequests ADD CONSTRAINT pk_cucorerequests PRIMARY KEY (id);";
91  $sqlRs = $this->query($sql);
92 
93  }
94  }
95 
96  /* To execute this you need to run the following command:
97  * php vendor/bin/phinx rollback (using correct path to phinx)
98  * Or, to roll back to a specific time:
99  * php vendor/bin/phinx rollback -t 20151123211207
100  */
101  public function down() {
102  // drop cucorerequests table
103  $this->dropTable("cucorerequests");
104  }
105 }
106 
107 ?>