Version23000Date20210930122352.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Migrations;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\DB\Types;
  11. use OCP\Migration\IOutput;
  12. use OCP\Migration\SimpleMigrationStep;
  13. class Version23000Date20210930122352 extends SimpleMigrationStep {
  14. private const TABLE_NAME = 'profile_config';
  15. /**
  16. * @param IOutput $output
  17. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  18. * @param array $options
  19. * @return null|ISchemaWrapper
  20. */
  21. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  22. /** @var ISchemaWrapper $schema */
  23. $schema = $schemaClosure();
  24. $hasTable = $schema->hasTable(self::TABLE_NAME);
  25. if (!$hasTable) {
  26. $table = $schema->createTable(self::TABLE_NAME);
  27. $table->addColumn('id', Types::BIGINT, [
  28. 'autoincrement' => true,
  29. 'notnull' => true,
  30. ]);
  31. $table->addColumn('user_id', Types::STRING, [
  32. 'notnull' => true,
  33. 'length' => 64,
  34. ]);
  35. $table->addColumn('config', Types::TEXT, [
  36. 'notnull' => true,
  37. ]);
  38. $table->setPrimaryKey(['id']);
  39. $table->addUniqueIndex(['user_id'], self::TABLE_NAME . '_user_id_idx');
  40. return $schema;
  41. }
  42. return null;
  43. }
  44. }