Skip to content

Commit

Permalink
Fixes yiisoft#13787: Added yii\db\Migration::$maxSqlOutputLength th…
Browse files Browse the repository at this point in the history
…at allows limiting number of characters for outputting SQL
  • Loading branch information
thiagotalma authored and samdark committed Jun 9, 2017
1 parent 78ec17f commit 1d06210
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Yii Framework 2 Change Log
- Bug #14248: `yii\console\controllers\MessageController` no longer outputs colorized filenames when console does not support text colorization (PowerGamer1)
- Bug #14264: Fixed a bug where `yii\log\Logger::calculateTimings()` was not accepting messages with array tokens (bizley)
- Chg #14201: `yii\console\controllers\MessageController::extractMessagesFromTokens()` is now protected (faenir)

- Enh #13787: Added `yii\db\Migration::$maxSqlOutputLength` that allows limiting number of characters for outputting SQL (thiagotalma)

2.0.12 June 05, 2017
--------------------
Expand Down
14 changes: 13 additions & 1 deletion framework/db/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use yii\base\Component;
use yii\di\Instance;
use yii\helpers\StringHelper;

/**
* Migration is the base class for representing a database migration.
Expand Down Expand Up @@ -65,6 +66,12 @@ class Migration extends Component implements MigrationInterface
*/
public $db = 'db';

/**
* @var int max number of characters of the SQL outputted. Useful for reduction of long statements and making
* console output more compact.
* @since 2.0.13
*/
public $maxSqlOutputLength;

/**
* Initializes the migration.
Expand Down Expand Up @@ -198,7 +205,12 @@ public function safeDown()
*/
public function execute($sql, $params = [])
{
echo " > execute SQL: $sql ...";
$sqlOutput = $sql;
if ($this->maxSqlOutputLength !== null) {
$sqlOutput = StringHelper::truncate($sql, $this->maxSqlOutputLength, '[... hidden]');
}

echo " > execute SQL: $sqlOutput ...";
$time = microtime(true);
$this->db->createCommand($sql)->bindValues($params)->execute();
echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
Expand Down

0 comments on commit 1d06210

Please sign in to comment.