Odyssey
2019042200_add_cuinfo_assets_table.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 /*
10  * Belatedly adding the cuinfo_assets table
11  */
12 
13 class AddCuinfoAssetsTable extends AbstractMigration {
14  public function up() {
15  if (!$this->hasTable('cuinfo_assets')) {
16  $cuinfo_assets = $this->table('cuinfo_assets', ['id' => false, 'primary_key' => ['user_name']]);
17  $cuinfo_assets
18  ->addColumn('user_name', 'string', ['limit' => 12])
19  ->addColumn('dec_31_assets', 'decimal', ['precision' => 4, 'scale' => 1])
20  ->create();
21  }
22  }
23 
24  public function down() {
25  if ($this->hasTable('cuinfo_assets')) {
26  $cuinfo_assets = $this->table('cuinfo_assets');
27  $cuinfo_assets
28  ->drop()
29  ->save();
30  }
31  }
32 }