Passed
Push — master ( 0b518c...5d9f70 )
by Benjamin
08:02 queued 13s
created

Install::removeTables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * @link      https://dukt.net/twitter/
4
 * @copyright Copyright (c) 2021, Dukt
5
 * @license   https://github.com/dukt/twitter/blob/master/LICENSE.md
6
 */
7
8
namespace dukt\twitter\migrations;
9
10
use Craft;
11
use craft\db\Migration;
12
13
class Install extends Migration
14
{
15
    // Public Properties
16
    // =========================================================================
17
18
    /**
19
     * @var string The database driver to use
20
     */
21
    public $driver;
22
23
    // Public Methods
24
    // =========================================================================
25
26
    /**
27
     * This method contains the logic to be executed when applying this migration.
28
     * This method differs from [[up()]] in that the DB logic implemented here will
29
     * be enclosed within a DB transaction.
30
     * Child classes may implement this method instead of [[up()]] if the DB logic
31
     * needs to be within a transaction.
32
     *
33
     * @return boolean return a false value to indicate the migration fails
34
     * and should not proceed further. All other return values mean the migration succeeds.
35
     */
36
    public function safeUp()
37
    {
38
        $this->driver = Craft::$app->getConfig()->getDb()->driver;
39
        $this->createTables();
40
41
        return true;
42
    }
43
44
    /**
45
     * This method contains the logic to be executed when removing this migration.
46
     * This method differs from [[down()]] in that the DB logic implemented here will
47
     * be enclosed within a DB transaction.
48
     * Child classes may implement this method instead of [[down()]] if the DB logic
49
     * needs to be within a transaction.
50
     *
51
     * @return boolean return a false value to indicate the migration fails
52
     * and should not proceed further. All other return values mean the migration succeeds.
53
     */
54
    public function safeDown()
55
    {
56
        $this->driver = Craft::$app->getConfig()->getDb()->driver;
57
        $this->removeTables();
58
59
        return true;
60
    }
61
62
    // Protected Methods
63
    // =========================================================================
64
65
    /**
66
     * Creates the tables needed for the Records used by the plugin
67
     *
68
     * @return void
69
     */
70
    protected function createTables()
71
    {
72
        $this->createTable(
73
            '{{%twitter_accounts}}',
74
            [
75
                'id' => $this->primaryKey(),
76
                'token' => $this->string(50),
77
                'tokenSecret' => $this->string(50),
78
                'dateCreated' => $this->dateTime()->notNull(),
79
                'dateUpdated' => $this->dateTime()->notNull(),
80
                'uid' => $this->uid()
81
            ]
82
        );
83
    }
84
85
    /**
86
     * Removes the tables needed for the Records used by the plugin
87
     *
88
     * @return void
89
     */
90
    protected function removeTables()
91
    {
92
        $this->dropTable('{{%twitter_accounts}}');
93
    }
94
}
95