Completed
Push — master ( 9d0cba...630902 )
by Paweł
02:59
created

safeDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * Handles the creation of table `account_note`.
7
 */
8
class m180628_061849_create_account_note_table extends Migration
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function safeUp()
14
    {
15
        $this->createTable('account_note', [
16
            'id' => $this->primaryKey(),
17
            'account_id' => $this->integer(),
18
            'user_id' => $this->integer(),
19
            'note' => $this->string(),
20
            'created_at' => $this->dateTime(),
21
        ]);
22
23
        $this->addForeignKey('fk_account_note_account', 'account_note', 'account_id', 'account', 'id', 'CASCADE');
24
        $this->addForeignKey('fk_account_note_user', 'account_note', 'user_id', 'user', 'id', 'CASCADE');
25
26
        $this->execute('INSERT INTO account_note (account_id, user_id, note, created_at) SELECT account.id, user.id, account.notes, DATE (NOW()) FROM `user`, account WHERE account.notes is not null');
27
28
        $this->dropColumn('account', 'notes');
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function safeDown()
35
    {
36
        $this->dropForeignKey('fk_account_note_account', 'account_note');
37
        $this->dropForeignKey('fk_account_note_user', 'account_note');
38
        $this->dropTable('account_note');
39
        $this->addColumn('account', 'notes', $this->string());
40
    }
41
}
42