m151030_133110_addCartView.php
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
use yii\db\Migration;
class m151030_133110_addCartView extends Migration
{
public function up()
{
$view = <<< MySQL
create view w_cart_view as
select `w_cart_bills`.`id`,
`w_cart_bills`.`account_id`,
unix_timestamp(`w_cart_bills`.`timestamp`) as `dt`,
`w_cart_bills`.`f1` as `user_name`,
`w_cart_bills`.`f3` as `user_mail`,
`w_cart`.`status` as `status_id`,
`w_dic_statuses`.`name` as `status`,
`w_cart`.`article`,`w_cart`.`brand`,`w_cart`.`descr`,
`w_importers`.`name` as `importer`,
`w_cart`.`count`,`w_cart`.`price`,
`w_cart`.`import_id`
from `w_cart`
inner join `w_importers` on `w_importers`.`id` = `w_cart`.`import_id`
inner join `w_cart_bills` on `w_cart_bills`.`id` = `w_cart`.`bill_id`
inner join `w_dic_statuses` on `w_dic_statuses`.`id` = `w_cart`.`status`;
MySQL;
$this->execute($view);
}
public function down()
{
// вернем все как было
$drop_view = 'drop view if exists w_cart_view';
$this->execute($drop_view);
}
}