Completed
Push — master ( d09d59...1a493b )
by Nate
11:08 queued 09:29
created

m190818_122247_visitor::safeDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\migrations;
10
11
use craft\db\Migration;
12
use flipbox\craft\hubspot\records\Visitor;
13
14
class m190818_122247_visitor extends Migration
15
{
16
    /**
17
     * @inheritdoc
18
     * @throws \yii\base\NotSupportedException
19
     * @throws \yii\db\Exception
20
     */
21
    public function safeUp()
22
    {
23
        $this->createTable(Visitor::tableName(), [
24
            'id' => $this->primaryKey(),
25
            'token' => $this->string()->notNull(),
26
            'contact' => $this->text(),
27
            'status' => $this->enum(
28
                'status',
29
                [
30
                    Visitor::STATUS_SUCCESSFUL,
31
                    Visitor::STATUS_PENDING,
32
                    Visitor::STATUS_ERROR,
33
                    Visitor::STATUS_NOT_FOUND
34
                ]
35
            )
36
                ->defaultValue(Visitor::STATUS_PENDING)
37
                ->notNull(),
38
            'connection' => $this->string(),
39
            'dateCreated' => $this->dateTime()->notNull(),
40
            'dateUpdated' => $this->dateTime()->notNull(),
41
            'uid' => $this->uid()
42
        ]);
43
44
        $this->createIndex(
45
            $this->db->getIndexName(Visitor::tableName(), 'token', true),
46
            Visitor::tableName(),
47
            'token',
48
            true
49
        );
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function safeDown()
56
    {
57
        $this->dropTableIfExists(Visitor::tableName());
58
        return true;
59
    }
60
}
61