|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Phinx\Migration\AbstractMigration; |
|
4
|
|
|
|
|
5
|
|
|
class GroupEventUnification extends AbstractMigration |
|
6
|
|
|
{ |
|
7
|
1 |
|
public function up() |
|
8
|
|
|
{ |
|
9
|
1 |
|
$this->table('messages') |
|
10
|
1 |
|
->addColumn('event_type', 'string', array('limit' => 50, 'null' => true, 'comment' => 'The type of the event, NULL if it\'s a message')) |
|
11
|
1 |
|
->update(); |
|
12
|
|
|
|
|
13
|
1 |
|
$this->execute("ALTER TABLE messages MODIFY player_from int(10) UNSIGNED DEFAULT NULL"); |
|
14
|
1 |
|
$this->execute("ALTER TABLE messages MODIFY status set('visible', 'hidden', 'deleted', 'reported') NOT NULL DEFAULT 'visible'"); |
|
15
|
|
|
|
|
16
|
|
|
// MySQL doesn't properly set the default value for sets, so we have to |
|
17
|
|
|
// do it manually |
|
18
|
1 |
|
$this->execute("UPDATE messages SET status = 'visible' WHERE status = ''"); |
|
19
|
|
|
|
|
20
|
1 |
|
$this->dropTable('group_events'); |
|
21
|
1 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function down() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->execute(" |
|
26
|
|
|
# Dump of table group_events |
|
27
|
|
|
# ------------------------------------------------------------ |
|
28
|
|
|
|
|
29
|
|
|
CREATE TABLE `group_events` ( |
|
30
|
|
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
31
|
|
|
`group_to` int(10) unsigned NOT NULL COMMENT 'The ID of the group where the event occured', |
|
32
|
|
|
`event` text NOT NULL COMMENT 'The serialized data of the event', |
|
33
|
|
|
`type` varchar(50) NOT NULL COMMENT 'The type of the event', |
|
34
|
|
|
`timestamp` datetime NOT NULL COMMENT 'The timestamp of when the event took place', |
|
35
|
|
|
`status` set('visible','deleted') NOT NULL DEFAULT 'visible' COMMENT 'That status of the group event', |
|
36
|
|
|
PRIMARY KEY (`id`), |
|
37
|
|
|
KEY `group_to` (`group_to`), |
|
38
|
|
|
CONSTRAINT `group_event_ibfk_1` FOREIGN KEY (`group_to`) REFERENCES `groups` (`id`) |
|
39
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
|
40
|
|
|
"); |
|
41
|
|
|
|
|
42
|
|
|
$this->table('messages')->removeColumn('event_type'); |
|
43
|
|
|
|
|
44
|
|
|
$this->execute("ALTER TABLE messages MODIFY status set('sent', 'hidden', 'deleted', 'reported') NOT NULL DEFAULT 'sent'"); |
|
45
|
|
|
$this->execute("UPDATE messages SET status = 'sent' WHERE status = ''"); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|