-
Notifications
You must be signed in to change notification settings - Fork 0
created two migrations for table_a and table_b #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <? | ||
|
|
||
| namespace console\controllers; | ||
|
|
||
| use yii; | ||
| use yii\console\Controller; | ||
| use yii\helpers\Console; | ||
| use yii\base\Security; | ||
|
|
||
| class FillTableAController extends Controller | ||
| { | ||
| //Records count to generate | ||
| private $records_count = 1000; | ||
|
|
||
| /** | ||
| * Run command: yii fill-table-a | ||
| * @return int | ||
| * @throws yii\base\Exception | ||
| * @throws yii\db\Exception | ||
| */ | ||
| public function actionIndex() | ||
| { | ||
| $security = new Security(); | ||
|
|
||
| Console::startProgress(0,$this->records_count); | ||
| for( $i=0;$i<$this->records_count;$i++ ) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for ($i = 0; $i <= $this->records_count; $i++) |
||
| Yii::$app->db->createCommand()->insert('table_a',['value'=>$security->generateRandomString(8)])->execute(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yii::$app->db->createCommand() и восемь константой, если не ясно почему могу объяснить |
||
| Console::updateProgress($i,$this->records_count); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Console::updateProgress($i, $this->records_count); |
||
| } | ||
| Console::endProgress('done'.PHP_EOL); | ||
|
|
||
| return 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут return 0; - не нужно. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| namespace console\controllers; | ||
|
|
||
| use yii; | ||
| use yii\console\Controller; | ||
| use yii\helpers\Console; | ||
|
|
||
| class MoveDataController extends Controller | ||
| { | ||
| /** | ||
| * Run command: yii move-data | ||
| * @return int | ||
| * @throws yii\db\Exception | ||
| */ | ||
| public function actionIndex() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public function actionIndex(): void |
||
| { | ||
| $data_a = Yii::$app->db->createCommand('SELECT * FROM table_a')->queryAll(); | ||
|
|
||
| Yii::$app->db->createCommand()->batchInsert('table_b',['id','value'],$data_a)->execute(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yii::$app->db->createCommand() |
||
|
|
||
| return 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return 0; - не нужен |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| use yii\db\Migration; | ||
|
|
||
| /** | ||
| * Class m190516_082608_create_table_a | ||
| */ | ||
| class m190516_082608_create_table_a extends Migration | ||
| { | ||
| public function safeUp() | ||
| { | ||
| $this->createTable( | ||
| 'table_a', | ||
| [ | ||
| 'id' => $this->primaryKey(), | ||
| 'value' => $this->string(), | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| public function safeDown() | ||
| { | ||
| $this->dropTable('table_a'); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| use yii\db\Migration; | ||
|
|
||
| /** | ||
| * Class m190516_090632_create_table_b | ||
| */ | ||
| class m190516_090632_create_table_b extends Migration | ||
| { | ||
| public function safeUp() | ||
| { | ||
| $this->createTable( | ||
| 'table_b', | ||
| [ | ||
| 'id' => $this->primaryKey(), | ||
| 'value' => $this->string(), | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| public function safeDown() | ||
| { | ||
| $this->dropTable('table_b'); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Console::startProgress(0, $this->records_count);
и ноль (цифры) желательно константой писать