|
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
|
|
|
|