1<?php 2 3declare(strict_types=1); 4 5namespace OCA\Mail\Migration; 6 7use Closure; 8use OCP\DB\ISchemaWrapper; 9use OCP\IDBConnection; 10use OCP\Migration\SimpleMigrationStep; 11use OCP\Migration\IOutput; 12 13class Version1020Date20191002091035 extends SimpleMigrationStep { 14 15 /** @var IDBConnection */ 16 protected $connection; 17 18 public function __construct(IDBConnection $connection) { 19 $this->connection = $connection; 20 } 21 22 /** 23 * @param IOutput $output 24 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` 25 * @param array $options 26 * 27 * @return ISchemaWrapper 28 */ 29 public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { 30 /** @var ISchemaWrapper $schema */ 31 $schema = $schemaClosure(); 32 33 $messagesTable = $schema->createTable('mail_messages'); 34 $messagesTable->addColumn('id', 'integer', [ 35 'autoincrement' => true, 36 'notnull' => true, 37 'length' => 20, 38 ]); 39 $messagesTable->addColumn('uid', 'integer', [ 40 'notnull' => true, 41 'length' => 4, 42 ]); 43 $messagesTable->addColumn('message_id', 'string', [ 44 'notnull' => false, 45 'length' => 255, 46 ]); 47 $messagesTable->addColumn('mailbox_id', 'string', [ 48 'notnull' => true, 49 'length' => 4, 50 ]); 51 $messagesTable->addColumn('subject', 'string', [ 52 'notnull' => true, 53 'length' => 255, 54 'default' => '', 55 ]); 56 $messagesTable->addColumn('sent_at', 'integer', [ 57 'notnull' => true, 58 'length' => 4, 59 ]); 60 $messagesTable->addColumn('flag_answered', 'boolean', [ 61 'notnull' => false, 62 'default' => false, 63 ]); 64 $messagesTable->addColumn('flag_deleted', 'boolean', [ 65 'notnull' => false, 66 'default' => false, 67 ]); 68 $messagesTable->addColumn('flag_draft', 'boolean', [ 69 'notnull' => false, 70 'default' => false, 71 ]); 72 $messagesTable->addColumn('flag_flagged', 'boolean', [ 73 'notnull' => false, 74 'default' => false, 75 ]); 76 $messagesTable->addColumn('flag_seen', 'boolean', [ 77 'notnull' => false, 78 'default' => false, 79 ]); 80 $messagesTable->addColumn('flag_forwarded', 'boolean', [ 81 'notnull' => false, 82 'default' => false, 83 ]); 84 $messagesTable->addColumn('flag_junk', 'boolean', [ 85 'notnull' => false, 86 'default' => false, 87 ]); 88 $messagesTable->addColumn('flag_notjunk', 'boolean', [ 89 'notnull' => false, 90 'default' => false, 91 ]); 92 $messagesTable->addColumn('updated_at', 'integer', [ 93 'notnull' => false, 94 'length' => 4, 95 ]); 96 $messagesTable->setPrimaryKey(['id']); 97 // We allow each UID just once 98 $messagesTable->addUniqueIndex([ 99 'uid', 100 'mailbox_id', 101 ]); 102 $messagesTable->addIndex(['sent_at'], 'mail_message_sent_idx'); 103 104 $recipientsTable = $schema->createTable('mail_recipients'); 105 $recipientsTable->addColumn('id', 'integer', [ 106 'autoincrement' => true, 107 'notnull' => true, 108 'length' => 20, 109 ]); 110 $recipientsTable->addColumn('message_id', 'integer', [ 111 'notnull' => true, 112 'length' => 20, 113 ]); 114 $recipientsTable->addColumn('type', 'integer', [ 115 'notnull' => true, 116 'length' => 2, 117 ]); 118 $recipientsTable->addColumn('label', 'string', [ 119 'notnull' => false, 120 'length' => 255, 121 ]); 122 $recipientsTable->addColumn('email', 'string', [ 123 'notnull' => true, 124 'length' => 255, 125 ]); 126 $recipientsTable->setPrimaryKey(['id']); 127 $recipientsTable->addIndex(['message_id'], 'mail_recipient_msg_id_idx'); 128 $recipientsTable->addIndex(['email'], 'mail_recipient_email_idx'); 129 130 $mailboxTable = $schema->getTable('mail_mailboxes'); 131 $mailboxTable->addColumn('sync_new_lock', 'integer', [ 132 'notnull' => false, 133 'length' => 4, 134 ]); 135 $mailboxTable->addColumn('sync_changed_lock', 'integer', [ 136 'notnull' => false, 137 'length' => 4, 138 ]); 139 $mailboxTable->addColumn('sync_vanished_lock', 'integer', [ 140 'notnull' => false, 141 'length' => 4, 142 ]); 143 $mailboxTable->addColumn('sync_new_token', 'string', [ 144 'notnull' => false, 145 'length' => 255, 146 ]); 147 $mailboxTable->addColumn('sync_changed_token', 'string', [ 148 'notnull' => false, 149 'length' => 255, 150 ]); 151 $mailboxTable->addColumn('sync_vanished_token', 'string', [ 152 'notnull' => false, 153 'length' => 255, 154 ]); 155 156 return $schema; 157 } 158} 159