|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright(c) 2016 Webtools Ltd |
|
4
|
|
|
* @copyright Copyright(c) 2018 Thamtech, LLC |
|
5
|
|
|
* @link https://github.com/thamtech/yii2-scheduler |
|
6
|
|
|
* @license https://opensource.org/licenses/MIT |
|
7
|
|
|
**/ |
|
8
|
|
|
|
|
9
|
|
|
use yii\db\Schema; |
|
10
|
|
|
use yii\db\Migration; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Create the scheduler task and log tables. |
|
14
|
|
|
*/ |
|
15
|
|
|
class m150510_090513_Scheduler extends Migration |
|
16
|
|
|
{ |
|
17
|
|
|
const TABLE_SCHEDULER_LOG = '{{%scheduler_log}}'; |
|
18
|
|
|
const TABLE_SCHEDULER_TASK = '{{%scheduler_task}}'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritdoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
public function safeUp() |
|
24
|
|
|
{ |
|
25
|
|
|
$tableOptions = null; |
|
26
|
|
|
if ($this->db->driverName === 'mysql') { |
|
27
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
|
28
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$this->createTable(self::TABLE_SCHEDULER_TASK, [ |
|
32
|
|
|
'id' => $this->primaryKey()->unsigned(), |
|
33
|
|
|
'name' => $this->string()->notNull(), |
|
34
|
|
|
'display_name' => $this->string()->notNull(), |
|
35
|
|
|
'schedule' => $this->string()->notNull(), |
|
36
|
|
|
'description' => $this->text()->notNull(), |
|
37
|
|
|
'status_id' => $this->integer()->unsigned()->notNull(), |
|
38
|
|
|
'started_at' => $this->dateTime()->null()->defaultValue(null), |
|
39
|
|
|
'last_run' => $this->dateTime()->null()->defaultValue(null), |
|
40
|
|
|
'next_run' => $this->dateTime()->null()->defaultValue(null), |
|
41
|
|
|
], $tableOptions); |
|
42
|
|
|
|
|
43
|
|
|
$this->createIndex('idx_name', self::TABLE_SCHEDULER_TASK, 'name', true); |
|
44
|
|
|
|
|
45
|
|
|
$this->createTable(self::TABLE_SCHEDULER_LOG, [ |
|
46
|
|
|
'id' => $this->bigPrimaryKey()->unsigned(), |
|
47
|
|
|
'scheduler_task_id' => $this->integer()->unsigned()->notNull(), |
|
48
|
|
|
'started_at' => $this->dateTime()->notNull()->defaultExpression('CURRENT_TIMESTAMP'), |
|
49
|
|
|
'ended_at' => $this->dateTime()->defaultValue(null), |
|
50
|
|
|
'output' => $this->text()->notNull(), |
|
51
|
|
|
'error' => $this->boolean()->defaultValue(false), |
|
52
|
|
|
], $tableOptions); |
|
53
|
|
|
|
|
54
|
|
|
$this->addForeignKey( |
|
55
|
|
|
'fk_scheduler_log_scheduler_task_id', // foreign key id |
|
56
|
|
|
self::TABLE_SCHEDULER_LOG, // this table |
|
57
|
|
|
'scheduler_task_id', // column in this table |
|
58
|
|
|
self::TABLE_SCHEDULER_TASK, // foreign table |
|
59
|
|
|
'id', // foreign column |
|
60
|
|
|
'CASCADE', // on delete |
|
61
|
|
|
'CASCADE' // on update |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function safeDown() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->dropTable(self::TABLE_SCHEDULER_LOG); |
|
71
|
|
|
$this->dropTable(self::TABLE_SCHEDULER_TASK); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|