Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
systems:yii2:migrations [2018/04/18 12:37]
smayr
systems:yii2:migrations [2018/04/19 10:07] (current)
smayr [New Notation]
Line 267: Line 267:
 class m160601_220000_skeleton extends Migration class m160601_220000_skeleton extends Migration
 { {
 +    private $useExtendedUserProfile = false;  // set it to your needs
 +    
     public function up()     public function up()
     {     {
Line 272: Line 274:
         $this->create_table_entry();         $this->create_table_entry();
         $this->create_table_product_hash();         $this->create_table_product_hash();
 +
 +        if ($this->useExtendedUserProfile) {
 +            $this->alter_user_table();
 +        }
     }     }
  
Line 277: Line 283:
     {     {
         $this->drop_tables();         $this->drop_tables();
 +        
         return true;         return true;
     }     }
Line 308: Line 315:
                 $this->truncateTable($curTable);   // delete all records                 $this->truncateTable($curTable);   // delete all records
                 $this->dropTable($curTable);       // drop table                 $this->dropTable($curTable);       // drop table
 +            }
 +            
 +            if ($this->useExtendedUserProfile) {
 +                // Restore any original table changes
 +                $this->restore_user_table();
             }             }
         }         }
 +    }
 +    
 +    private function alter_user_table()
 +    {
 +        $this->addColumn('{{%user}}', 'address1', $this->string());
 +        $this->addColumn('{{%user}}', 'address2', $this->string());
 +        $this->addColumn('{{%user}}', 'city', $this->string());
 +        $this->addColumn('{{%user}}', 'state_prov', $this->string());
 +        $this->addColumn('{{%user}}', 'postal_code', $this->string());
 +        $this->addColumn('{{%user}}', 'country', $this->string());
 +        // $this->addColumn('{{%user}}', 'company_name', $this->string());
 +        // $this->addColumn('{{%user}}', 'organization_name', $this->string());
 +        // $this->addColumn('{{%user}}', 'school_name', $this->string());
 +        // $this->addColumn('{{%user}}', 'job_title', $this->string());
 +        $this->addColumn('{{%user}}', 'receive_newsletter', $this->tinyInteger()->notNull()->defaultValue(1));
 +    }
 +    
 +    private function restore_user_table()
 +    {
 +        $this->dropColumn('{{%user}}', 'address1');
 +        $this->dropColumn('{{%user}}', 'address2');
 +        $this->dropColumn('{{%user}}', 'city');
 +        $this->dropColumn('{{%user}}', 'state_prov');
 +        $this->dropColumn('{{%user}}', 'postal_code');
 +        $this->dropColumn('{{%user}}', 'country');
 +        $this->dropColumn('{{%user}}', 'company_name');
 +        $this->dropColumn('{{%user}}', 'job_title');
 +        $this->dropColumn('{{%user}}', 'receive_newsletter');
     }     }
          
Line 550: Line 590:
 // Add reference_code to all records // Add reference_code to all records
 foreach((new Query)->from('price')->each() as $price) { foreach((new Query)->from('price')->each() as $price) {
-    $this->update('price', ['reference_code' => $price->item_code], ['id' => $price->id]);+    $this->update('{{%price}}', ['reference_code' => $price->item_code], ['id' => $price->id]);
 } }
 </code> </code>
Line 559: Line 599:
 foreach((new Query)->from('price')->each() as $price) { foreach((new Query)->from('price')->each() as $price) {
   // DELETE price WHERE reference_code = 'partUnknown', id = :price_id   // DELETE price WHERE reference_code = 'partUnknown', id = :price_id
-  $this->delete('price', ['reference_code' => 'partUnknown', 'id' => $price->id]);+  $this->delete('{{%price}}', ['reference_code' => 'partUnknown', 'id' => $price->id]);
 } }
 </code> </code>
Line 565: Line 605:
  
 === Create SQL View === === Create SQL View ===
 +Instead of viewing all entry records, you can create a view with a subset of them.  For example, if we want all the entry records for brand 'Acme', we would create the 'acme_entry' view as follows:
 <code php> <code php>
 private function create_view_acme_entry() private function create_view_acme_entry()