Odyssey
2017111000_fixcurdcstatus.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 fixcurdcstatus extends AbstractMigration {
10 
11  /*
12  * add the column 'user_id' to curdcstatus table.
13  */
14 
15 public function up() {
16 
17  if (!$this->hasTable("curdcstatus"))
18  {
19  print "Table doesn't exist. Nothing done.";
20  }
21  else
22  {
23  $table= $this->table('curdcstatus');
24 
25  if (!$table->hasColumn('user_id'))
26  {
27  print "Adding user_id to table.\n";
28  $this->query('DROP table curdcstatus');
29  $sql = "CREATE TABLE curdcstatus (
30  depositid integer NOT NULL,
31  cu character(12) NOT NULL,
32  user_id integer NOT NULL,
33  accountnumber character(12) NOT NULL,
34  rdcvendor character varying(20) NOT NULL,
35  starttime timestamp with time zone DEFAULT now() NOT NULL,
36  lastupdate timestamp with time zone DEFAULT now() NOT NULL,
37  frontpath character varying(100),
38  frontaccept character(1),
39  backpath character varying(100),
40  backaccept character(1),
41  amount numeric(11,2),
42  amountaccept character(1),
43  acctid character varying(100),
44  status character varying,
45  vendorinfo character varying
46  );";
47 
48  $this->query("$sql");
49  $sql = "CREATE SEQUENCE curdcstatus_depositid_seq
50  START WITH 1
51  INCREMENT BY 1
52  NO MINVALUE
53  NO MAXVALUE
54  CACHE 1;";
55  $this->query("$sql");
56  $this->query("ALTER SEQUENCE curdcstatus_depositid_seq OWNED BY curdcstatus.depositid;");
57  $this->query("ALTER TABLE ONLY curdcstatus ALTER COLUMN depositid SET DEFAULT nextval('curdcstatus_depositid_seq'::regclass);");
58  $this->query("ALTER TABLE ONLY curdcstatus ADD CONSTRAINT curdcstatus_pkey PRIMARY KEY (depositid);");
59  }
60  }
61  }
62 
63 
64  /* To execute this you need to run the following command:
65  * php vendor/bin/phinx rollback (using correct path to phinx)
66  * Or, to roll back to a specific time:
67  * php vendor/bin/phinx rollback -t 20151123211207
68  */
69  public function down() {
70 
71  if (!$this->hasTable("curdcstatus"))
72  {
73  print "Table doesn't exist. Nothing done.";
74  }
75  else
76  {
77  $table= $this->table('curdcstatus');
78 
79  if ($table->hasColumn('user_id'))
80  {
81  print "Dropping user_id from table.\n";
82  $table->removeColumn('user_id')
83  ->save();
84  }
85  }
86  }
87 }
88 
89 ?>