Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
systems:yii2:migrations [2018/04/18 11:07] smayr |
systems:yii2:migrations [2018/04/19 10:07] (current) smayr [New Notation] |
||
---|---|---|---|
Line 42: | Line 42: | ||
//return true; | //return true; | ||
| | ||
- | $connection | + | $connection = Yii:: |
- | $dbSchema | + | $dbSchema |
- | $allTableNames | + | $allTables |
| | ||
- | // Available Tables: must be listed in reverse creation order | + | // Available Tables: must be listed in reverse creation order, |
- | //$availTables | + | // and dropping tables with foreign keys first. |
- | $availTables | + | //$targetTables |
+ | $targetTables | ||
| | ||
- | foreach($availTables | + | |
- | if (in_array($curTable, | + | echo " |
+ | |||
+ | | ||
+ | echo " | ||
+ | if (in_array($curTable, | ||
//if ($curTable == ' | //if ($curTable == ' | ||
//{ | //{ | ||
Line 262: | Line 267: | ||
class m160601_220000_skeleton extends Migration | class m160601_220000_skeleton extends Migration | ||
{ | { | ||
+ | private $useExtendedUserProfile = false; | ||
+ | | ||
public function up() | public function up() | ||
{ | { | ||
Line 267: | Line 274: | ||
$this-> | $this-> | ||
$this-> | $this-> | ||
+ | |||
+ | if ($this-> | ||
+ | $this-> | ||
+ | } | ||
} | } | ||
Line 272: | Line 283: | ||
{ | { | ||
$this-> | $this-> | ||
+ | | ||
return true; | return true; | ||
} | } | ||
Line 277: | Line 289: | ||
public function drop_tables() | public function drop_tables() | ||
{ | { | ||
- | $connection | + | $connection = Yii:: |
- | $dbSchema | + | $dbSchema |
- | $allTableNames | + | $allTables |
| | ||
- | // Available Tables: must be listed in reverse creation order, and dropping tables with foreign keys first | + | // Available Tables: must be listed in reverse creation order, |
- | $availTables | + | // and dropping tables with foreign keys first. |
+ | | ||
+ | $targetTables= [ | ||
+ | $this-> | ||
+ | $this-> | ||
+ | | ||
| | ||
- | foreach($availTables | + | |
- | if (in_array($curTable, | + | echo " |
- | if ($curTable == 'entry' | + | |
- | // | + | |
+ | echo " | ||
+ | if (in_array($curTable, | ||
+ | if ($curTable == $this-> | ||
+ | // | ||
+ | } | ||
+ | if ($curTable == $this-> | ||
+ | // | ||
} | } | ||
$this-> | $this-> | ||
$this-> | $this-> | ||
+ | } | ||
+ | | ||
+ | if ($this-> | ||
+ | // Restore any original table changes | ||
+ | $this-> | ||
} | } | ||
} | } | ||
+ | } | ||
+ | | ||
+ | private function alter_user_table() | ||
+ | { | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | // $this-> | ||
+ | // $this-> | ||
+ | // $this-> | ||
+ | // $this-> | ||
+ | $this-> | ||
+ | } | ||
+ | | ||
+ | private function restore_user_table() | ||
+ | { | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
} | } | ||
| | ||
Line 320: | Line 377: | ||
// AUTO_INCREMENT=1; | // AUTO_INCREMENT=1; | ||
| | ||
- | $this-> | + | $this-> |
' | ' | ||
' | ' | ||
Line 334: | Line 391: | ||
| | ||
// insert data as a row | // insert data as a row | ||
- | $this-> | + | $this-> |
" | " | ||
" | " | ||
Line 367: | Line 424: | ||
// AUTO_INCREMENT=1; | // AUTO_INCREMENT=1; | ||
| | ||
- | $this-> | + | $this-> |
' | ' | ||
' | ' | ||
Line 376: | Line 433: | ||
| | ||
// insert data as a row | // insert data as a row | ||
- | // | + | // |
// " | // " | ||
// " | // " | ||
Line 385: | Line 442: | ||
// table name, column names, column values | // table name, column names, column values | ||
$db = Yii:: | $db = Yii:: | ||
- | $db-> | + | $db-> |
[' | [' | ||
[ | [ | ||
Line 422: | Line 479: | ||
Method 1: | Method 1: | ||
<code php> | <code php> | ||
- | $this-> | + | $this-> |
' | ' | ||
' | ' | ||
Line 436: | Line 493: | ||
Method 2: | Method 2: | ||
<code php> | <code php> | ||
- | $this-> | + | $this-> |
' | ' | ||
' | ' | ||
Line 519: | Line 576: | ||
// USAGE: batchInsert(table_name, | // USAGE: batchInsert(table_name, | ||
$db = Yii:: | $db = Yii:: | ||
- | $db-> | + | $db-> |
[' | [' | ||
[ | [ | ||
Line 533: | Line 590: | ||
// Add reference_code to all records | // Add reference_code to all records | ||
foreach((new Query)-> | foreach((new Query)-> | ||
- | $this-> | + | $this-> |
} | } | ||
</ | </ | ||
Line 542: | Line 599: | ||
foreach((new Query)-> | foreach((new Query)-> | ||
// DELETE price WHERE reference_code = ' | // DELETE price WHERE reference_code = ' | ||
- | $this-> | + | $this-> |
} | } | ||
</ | </ | ||
Line 548: | 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 ' | ||
<code php> | <code php> | ||
private function create_view_acme_entry() | private function create_view_acme_entry() |