Commit afcbaa24d5ec4b1821ce2b703f28f55f265cbf0e
1 parent
3be5e214
add migration for FK currency in Importers table
Showing
2 changed files
with
29 additions
and
1 deletions
Show diff stats
console/migrations/m150925_111922_add_foreign_key_ImportFiles.php
| @@ -22,7 +22,7 @@ class m150925_111922_add_foreign_key_ImportFiles extends Migration | @@ -22,7 +22,7 @@ class m150925_111922_add_foreign_key_ImportFiles extends Migration | ||
| 22 | $this->addForeignKey('importer_fk', '{{%importers_files}}', 'importer_id', '{{%importers}}', 'id'); | 22 | $this->addForeignKey('importer_fk', '{{%importers_files}}', 'importer_id', '{{%importers}}', 'id'); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | - public function down() | 25 | + public function safeDown() |
| 26 | { | 26 | { |
| 27 | $this->dropForeignKey('importer_fk', '{{%importers_files}}'); | 27 | $this->dropForeignKey('importer_fk', '{{%importers_files}}'); |
| 28 | } | 28 | } |
console/migrations/m151016_130143_add_fk_currency_to_Importers.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Schema; | ||
| 4 | +use yii\db\Migration; | ||
| 5 | + | ||
| 6 | +class m151016_130143_add_fk_currency_to_Importers extends Migration | ||
| 7 | +{ | ||
| 8 | + public function safeUp() | ||
| 9 | + { | ||
| 10 | +// // сначала отберем записи которых нет уже в поставщиках | ||
| 11 | +// $id_arr = (new \yii\db\Query()) | ||
| 12 | +// ->select(['{{%importers_files}}.id']) | ||
| 13 | +// ->from('{{%importers_files}}') | ||
| 14 | +// ->leftJoin('{{%importers}}', 'importer_id = {{%importers}}.id') | ||
| 15 | +// ->where(['name' => null]) | ||
| 16 | +// ->all(); | ||
| 17 | +// $id_arr = array_column($id_arr,'id'); | ||
| 18 | +// // удалим их | ||
| 19 | +// $this->delete('{{%importers_files}}',['id' => $id_arr]); | ||
| 20 | + | ||
| 21 | + $this->addForeignKey('currency_fk', '{{%importers}}', 'currency_id', '{{%currency}}', 'id'); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public function safeDown() | ||
| 25 | + { | ||
| 26 | + $this->dropForeignKey('currency_fk', '{{%importers}}'); | ||
| 27 | + } | ||
| 28 | +} |