1<?php 2 3declare(strict_types=1); 4/** 5 * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> 6 * 7 * @author Roeland Jago Douma <roeland@famdouma.nl> 8 * 9 * @license GNU AGPL version 3 or any later version 10 * 11 * This program is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Affero General Public License as 13 * published by the Free Software Foundation, either version 3 of the 14 * License, or (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Affero General Public License for more details. 20 * 21 * You should have received a copy of the GNU Affero General Public License 22 * along with this program. If not, see <http://www.gnu.org/licenses/>. 23 * 24 */ 25 26namespace OCA\TwoFactorNextcloudNotification\Migration; 27 28use Doctrine\DBAL\Types\Types; 29use OCA\TwoFactorNextcloudNotification\AppInfo\Application; 30use OCP\DB\ISchemaWrapper; 31use OCP\Migration\SimpleMigrationStep; 32use OCP\Migration\IOutput; 33 34class Version000100Date20180411172140 extends SimpleMigrationStep { 35 36 /** 37 * @param IOutput $output 38 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` 39 * @param array $options 40 * @return null|ISchemaWrapper 41 */ 42 public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { 43 /** @var ISchemaWrapper $schema */ 44 $schema = $schemaClosure(); 45 46 if (!$schema->hasTable(Application::APP_ID . '_tokens')) { 47 $table = $schema->createTable(Application::APP_ID . '_tokens'); 48 49 $table->addColumn('id', Types::INTEGER, [ 50 'autoincrement' => true, 51 'notnull' => true, 52 'length' => 20, 53 ]); 54 $table->addColumn('user_id', Types::STRING, [ 55 'notnull' => true, 56 'length' => 64, 57 ]); 58 $table->addColumn('token', Types::STRING, [ 59 'notnull' => true, 60 'length' => 40, 61 ]); 62 $table->addColumn('timestamp', Types::INTEGER, [ 63 'notnull' => true, 64 'length' => 20, 65 ]); 66 $table->addColumn('status', Types::INTEGER, [ 67 'notnull' => true, 68 'length' => 2, 69 ]); 70 71 $table->setPrimaryKey(['id'], Application::APP_ID . '_tokens_id_idx'); 72 $table->addIndex(['token'], Application::APP_ID . '_tokens_token_idx'); 73 74 return $schema; 75 } 76 return null; 77 } 78} 79