Commit b8cb5e2a by Alexander Makarov

Fixes #4263: Added migration and SQL schema files for `yii\log\DbTarget`

parent 05d54731
...@@ -20,10 +20,11 @@ Yii Framework 2 Change Log ...@@ -20,10 +20,11 @@ Yii Framework 2 Change Log
- Bug #5925: `ArrayHelper::htmlEncode()` does not work properly when the value being encoded is a nested array (tebazil) - Bug #5925: `ArrayHelper::htmlEncode()` does not work properly when the value being encoded is a nested array (tebazil)
- Bug: Gii console command help information does not contain global options (qiangxue) - Bug: Gii console command help information does not contain global options (qiangxue)
- Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark) - Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark)
- Enh #4263: Added migration and SQL schema files for `yii\log\DbTarget` (samdark)
- Enh #4457: Added support for using noscript for css files registered through asset bundles and Html helper (samdark)
- Enh #5223: Query builder now supports selecting sub-queries as columns (qiangxue) - Enh #5223: Query builder now supports selecting sub-queries as columns (qiangxue)
- Enh #5587: `json_encode` is now used with `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE` where it makes sense, also - Enh #5587: `json_encode` is now used with `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE` where it makes sense, also
it is now default for `Json::encode()` (samdark) it is now default for `Json::encode()` (samdark)
- Enh #4457: Added support for using noscript for css files registered through asset bundles and Html helper (samdark)
- Enh #5600: Allow configuring debug panels in `yii\debug\Module::panels` as panel class name strings (qiangxue) - Enh #5600: Allow configuring debug panels in `yii\debug\Module::panels` as panel class name strings (qiangxue)
- Enh #5613: Added `--overwrite` option to Gii console command to support overwriting all files (motin, qiangxue) - Enh #5613: Added `--overwrite` option to Gii console command to support overwriting all files (motin, qiangxue)
- Enh #5646: Call `yii\base\ErrorHandler::unregister()` instead of `restore_*_handlers` directly (aivus) - Enh #5646: Call `yii\base\ErrorHandler::unregister()` instead of `restore_*_handlers` directly (aivus)
...@@ -31,6 +32,7 @@ Yii Framework 2 Change Log ...@@ -31,6 +32,7 @@ Yii Framework 2 Change Log
- Enh #5770: Added more PHP error names for `ErrorException` (mongosoft) - Enh #5770: Added more PHP error names for `ErrorException` (mongosoft)
- Enh #5806: Allow `Html::encode()` to be used when the application is not started (qiangxue) - Enh #5806: Allow `Html::encode()` to be used when the application is not started (qiangxue)
- Enh: `Console::confirm()` now uses `Console::stdout()` instead of `echo` to be consistent with all other functions (cebe) - Enh: `Console::confirm()` now uses `Console::stdout()` instead of `echo` to be consistent with all other functions (cebe)
- Enh: `yii\rbac\DbManager` migration now uses database component specified in component settings instead of always using default `db` (samdark)
- Chg #3630: `yii\db\Command::queryInternal()` is now protected (samdark) - Chg #3630: `yii\db\Command::queryInternal()` is now protected (samdark)
- Chg #5508: Dropped the support for the `--append` option for the `fixture` command (qiangxue) - Chg #5508: Dropped the support for the `--append` option for the `fixture` command (qiangxue)
- Chg #5874: Upgraded Twitter Bootstrap to 3.3.x (samdark) - Chg #5874: Upgraded Twitter Bootstrap to 3.3.x (samdark)
......
...@@ -16,8 +16,15 @@ use yii\helpers\VarDumper; ...@@ -16,8 +16,15 @@ use yii\helpers\VarDumper;
/** /**
* DbTarget stores log messages in a database table. * DbTarget stores log messages in a database table.
* *
* By default, DbTarget stores the log messages in a DB table named 'log'. This table * The database connection is specified by [[db]]. Database schema could be initialized by applying migration:
* must be pre-created. The table name can be changed by setting the [[logTable]] property. *
* ```
* yii migrate --migrationPath=@yii/log/migrations/
* ```
*
* If you don't want to use migration and need SQL instead, files for all databases are in migrations directory.
*
* You may change the name of the table used to store the data by setting [[logTable]].
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
...@@ -31,29 +38,7 @@ class DbTarget extends Target ...@@ -31,29 +38,7 @@ class DbTarget extends Target
*/ */
public $db = 'db'; public $db = 'db';
/** /**
* @var string name of the DB table to store cache content. * @var string name of the DB table to store cache content. Defaults to "log".
* The table should be pre-created as follows:
*
* ~~~
* CREATE TABLE log (
* id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
* level INTEGER,
* category VARCHAR(255),
* log_time INTEGER,
* prefix TEXT,
* message TEXT,
* INDEX idx_log_level (level),
* INDEX idx_log_category (category)
* )
* ~~~
*
* Note that the 'id' column must be created as an auto-incremental column.
* The above SQL uses the MySQL syntax. If you are using other DBMS, you need
* to adjust it accordingly. For example, in PostgreSQL, it should be `id SERIAL PRIMARY KEY`.
*
* The indexes declared above are not required. They are mainly used to improve the performance
* of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`).
*/ */
public $logTable = '{{%log}}'; public $logTable = '{{%log}}';
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
use yii\base\InvalidConfigException;
use yii\db\Schema;
use yii\db\Migration;
use yii\log\DbTarget;
/**
* Initializes log table.
*
* The indexes declared are not required. They are mainly used to improve the performance
* of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`).
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0.1
*/
class m141106_185632_log_init extends Migration
{
/**
* @var DbTarget[]
*/
private $dbTargets = [];
/**
* @throws InvalidConfigException
* @return DbTarget[]
*/
protected function getDbTargets()
{
if ($this->dbTargets === []) {
$log = Yii::$app->getLog();
foreach ($log->targets as $target) {
if ($target instanceof DbTarget) {
$this->dbTargets[] = $target;
}
}
if ($this->dbTargets === []) {
throw new InvalidConfigException('You should configure "log" component to use one or more database targets before executing this migration.');
}
}
return $this->dbTargets;
}
public function up()
{
$targets = $this->getDbTargets();
foreach ($targets as $target) {
$this->db = $target->db;
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable($target->logTable, [
'id' => Schema::TYPE_BIGPK,
'level' => Schema::TYPE_INTEGER,
'category' => Schema::TYPE_STRING,
'log_time' => Schema::TYPE_INTEGER,
'prefix' => Schema::TYPE_TEXT,
'message' => Schema::TYPE_TEXT,
], $tableOptions);
$this->createIndex('idx_log_level', $target->logTable, 'level');
$this->createIndex('idx_log_category', $target->logTable, 'category');
}
}
public function down()
{
$targets = $this->getDbTargets();
foreach ($targets as $target) {
$this->db = $target->db;
$this->dropTable($target->logTable);
}
}
}
/**
* Database schema required by \yii\log\DbTarget.
*
* The indexes declared are not required. They are mainly used to improve the performance
* of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`).
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @link http://www.yiiframework.com/
* @copyright 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @since 2.0.1
*/
drop table if exists [log];
create table [log]
(
[id] bigint IDENTITY PRIMARY KEY,
[level] integer,
[category] varchar(255),
[log_time] integer,
[prefix] text,
[message] text
);
create index [idx_log_level] on [log] ([level]);
create index [idx_log_category] on [log] ([category]);
/**
* Database schema required by \yii\log\DbTarget.
*
* The indexes declared are not required. They are mainly used to improve the performance
* of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`).
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @link http://www.yiiframework.com/
* @copyright 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @since 2.0.1
*/
drop table if exists `log`;
create table `log`
(
`id` bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`level` integer,
`category` varchar(255),
`log_time` integer,
`prefix` text,
`message` text,
key `idx_log_level` (`level`),
key `idx_log_category` (`category`)
) engine InnoDB;
/**
* Database schema required by \yii\log\DbTarget.
*
* The indexes declared are not required. They are mainly used to improve the performance
* of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`).
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @link http://www.yiiframework.com/
* @copyright 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @since 2.0.1
*/
drop table if exists "log";
create table "log"
(
"id" number(20) NOT NULL PRIMARY KEY,
"level" integer,
"category" varchar(255),
"log_time" integer,
"prefix" text,
"message" text,
key "idx_log_level" ("level"),
key "idx_log_category" ("category")
);
/**
* Database schema required by \yii\log\DbTarget.
*
* The indexes declared are not required. They are mainly used to improve the performance
* of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`).
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @link http://www.yiiframework.com/
* @copyright 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @since 2.0.1
*/
drop table if exists "log";
create table "log"
(
"id" bigserial NOT NULL PRIMARY KEY,
"level" integer,
"category" varchar(255),
"log_time" integer,
"prefix" text,
"message" text
);
create index "idx_log_level" on "log" ("level");
create index "idx_log_category" on "log" ("category");
\ No newline at end of file
/**
* Database schema required by \yii\log\DbTarget.
*
* The indexes declared are not required. They are mainly used to improve the performance
* of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`).
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @link http://www.yiiframework.com/
* @copyright 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @since 2.0.1
*/
drop table if exists "log";
create table "log"
(
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
"level" integer,
"category" varchar(255),
"log_time" integer,
"prefix" text,
"message" text
);
create index "idx_log_level" on "log" ("level");
create index "idx_log_category" on "log" ("category");
\ No newline at end of file
...@@ -33,6 +33,7 @@ class m140506_102106_rbac_init extends \yii\db\Migration ...@@ -33,6 +33,7 @@ class m140506_102106_rbac_init extends \yii\db\Migration
public function up() public function up()
{ {
$authManager = $this->getAuthManager(); $authManager = $this->getAuthManager();
$this->db = $authManager->db;
$tableOptions = null; $tableOptions = null;
if ($this->db->driverName === 'mysql') { if ($this->db->driverName === 'mysql') {
...@@ -81,6 +82,7 @@ class m140506_102106_rbac_init extends \yii\db\Migration ...@@ -81,6 +82,7 @@ class m140506_102106_rbac_init extends \yii\db\Migration
public function down() public function down()
{ {
$authManager = $this->getAuthManager(); $authManager = $this->getAuthManager();
$this->db = $authManager->db;
$this->dropTable($authManager->assignmentTable); $this->dropTable($authManager->assignmentTable);
$this->dropTable($authManager->itemChildTable); $this->dropTable($authManager->itemChildTable);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment