init
This commit is contained in:
94
vendor/yiisoft/yii2/log/migrations/m141106_185632_log_init.php
vendored
Normal file
94
vendor/yiisoft/yii2/log/migrations/m141106_185632_log_init.php
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
<?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\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[] Targets to create log table for
|
||||
*/
|
||||
private $dbTargets = [];
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @return DbTarget[]
|
||||
*/
|
||||
protected function getDbTargets()
|
||||
{
|
||||
if ($this->dbTargets === []) {
|
||||
$log = Yii::$app->getLog();
|
||||
|
||||
$usedTargets = [];
|
||||
foreach ($log->targets as $target) {
|
||||
if ($target instanceof DbTarget) {
|
||||
$currentTarget = [
|
||||
$target->db,
|
||||
$target->logTable,
|
||||
];
|
||||
if (!in_array($currentTarget, $usedTargets, true)) {
|
||||
// do not create same table twice
|
||||
$usedTargets[] = $currentTarget;
|
||||
$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()
|
||||
{
|
||||
foreach ($this->getDbTargets() 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' => $this->bigPrimaryKey(),
|
||||
'level' => $this->integer(),
|
||||
'category' => $this->string(),
|
||||
'log_time' => $this->double(),
|
||||
'prefix' => $this->text(),
|
||||
'message' => $this->text(),
|
||||
], $tableOptions);
|
||||
|
||||
$this->createIndex('idx_log_level', $target->logTable, 'level');
|
||||
$this->createIndex('idx_log_category', $target->logTable, 'category');
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
foreach ($this->getDbTargets() as $target) {
|
||||
$this->db = $target->db;
|
||||
|
||||
$this->dropTable($target->logTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
vendor/yiisoft/yii2/log/migrations/schema-mssql.sql
vendored
Normal file
29
vendor/yiisoft/yii2/log/migrations/schema-mssql.sql
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
if object_id('[log]', 'U') is not null
|
||||
drop table [log];
|
||||
|
||||
create table [log]
|
||||
(
|
||||
[id] bigint IDENTITY PRIMARY KEY,
|
||||
[level] integer,
|
||||
[category] varchar(255),
|
||||
[log_time] float,
|
||||
[prefix] text,
|
||||
[message] text
|
||||
);
|
||||
|
||||
create index [idx_log_level] on [log] ([level]);
|
||||
create index [idx_log_category] on [log] ([category]);
|
||||
27
vendor/yiisoft/yii2/log/migrations/schema-mysql.sql
vendored
Normal file
27
vendor/yiisoft/yii2/log/migrations/schema-mysql.sql
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 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` double,
|
||||
`prefix` text,
|
||||
`message` text,
|
||||
key `idx_log_level` (`level`),
|
||||
key `idx_log_category` (`category`)
|
||||
) engine InnoDB;
|
||||
27
vendor/yiisoft/yii2/log/migrations/schema-oci.sql
vendored
Normal file
27
vendor/yiisoft/yii2/log/migrations/schema-oci.sql
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 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" number,
|
||||
"prefix" text,
|
||||
"message" text,
|
||||
key "idx_log_level" ("level"),
|
||||
key "idx_log_category" ("category")
|
||||
);
|
||||
28
vendor/yiisoft/yii2/log/migrations/schema-pgsql.sql
vendored
Normal file
28
vendor/yiisoft/yii2/log/migrations/schema-pgsql.sql
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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" double precision,
|
||||
"prefix" text,
|
||||
"message" text
|
||||
);
|
||||
|
||||
create index "idx_log_level" on "log" ("level");
|
||||
create index "idx_log_category" on "log" ("category");
|
||||
28
vendor/yiisoft/yii2/log/migrations/schema-sqlite.sql
vendored
Normal file
28
vendor/yiisoft/yii2/log/migrations/schema-sqlite.sql
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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" double,
|
||||
"prefix" text,
|
||||
"message" text
|
||||
);
|
||||
|
||||
create index "idx_log_level" on "log" ("level");
|
||||
create index "idx_log_category" on "log" ("category");
|
||||
Reference in New Issue
Block a user