Completed
Push — master ( 9b0a79...008d1c )
by vistart
04:23
created

m170406_140953_CreateUserProfileView::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 *   _   __ __ _____ _____ ___  ____  _____
5
 *  | | / // // ___//_  _//   ||  __||_   _|
6
 *  | |/ // /(__  )  / / / /| || |     | |
7
 *  |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\user\migrations;
14
15
use rhosocial\user\User;
16
use rhosocial\user\Profile;
17
18
/**
19
 * @version 1.0
20
 * @author vistart <[email protected]>
21
 */
22
class m170406_140953_CreateUserProfileView extends Migration
23
{
24
    public function up()
25
    {
26
        $tablePrefix = $this->db->tablePrefix;
27
        $userTableName = $tablePrefix . 'user';
28
        $profileTableName = $tablePrefix . 'profile';
29
$sql = <<<EOT
30
CREATE 
31
VIEW `UserProfileView`AS 
32
SELECT
33
`t_user`.guid,
34
`t_user`.id,
35
`t_user`.pass_hash,
36
`t_user`.ip,
37
`t_user`.ip_type,
38
`t_user`.created_at,
39
`t_user`.updated_at,
40
`t_user`.auth_key,
41
`t_user`.access_token,
42
`t_user`.password_reset_token,
43
`t_user`.`status`,
44
`t_user`.type,
45
`t_user`.source,
46
`t_profile`.nickname,
47
`t_profile`.first_name,
48
`t_profile`.last_name,
49
`t_profile`.gravatar_type,
50
`t_profile`.gravatar,
51
`t_profile`.gender,
52
`t_profile`.timezone,
53
`t_profile`.individual_sign,
54
`t_profile`.created_at AS profile_created_at,
55
`t_profile`.updated_at AS profile_updated_at
56
FROM
57
`$userTableName` AS `t_user`
58
INNER JOIN `$profileTableName` AS `t_profile` ON `t_profile`.guid = `t_user`.guid ;
59
EOT;
60
        $this->execute($sql);
61
    }
62
63
    public function down()
64
    {
65
        $this->execute("DROP VIEW `UserProfileView`;");
66
    }
67
68
    /*
69
    // Use safeUp/safeDown to run migration code within a transaction
70
    public function safeUp()
71
    {
72
    }
73
74
    public function safeDown()
75
    {
76
    }
77
    */
78
}
79