|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\Richdocuments\Migration; |
| 11 | + |
| 12 | +use Closure; |
| 13 | +use OCP\DB\ISchemaWrapper; |
| 14 | +use OCP\Migration\IOutput; |
| 15 | +use OCP\Migration\SimpleMigrationStep; |
| 16 | +use Override; |
| 17 | + |
| 18 | +/** |
| 19 | + * Update version column in richdocuments_wopi table to support alphanumeric versions |
| 20 | + */ |
| 21 | +class Version10000Date20251217143558 extends SimpleMigrationStep { |
| 22 | + |
| 23 | + /** |
| 24 | + * @param IOutput $output |
| 25 | + * @param Closure(): ISchemaWrapper $schemaClosure |
| 26 | + * @param array $options |
| 27 | + */ |
| 28 | + #[Override] |
| 29 | + public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @param IOutput $output |
| 34 | + * @param Closure(): ISchemaWrapper $schemaClosure |
| 35 | + * @param array $options |
| 36 | + * @return null|ISchemaWrapper |
| 37 | + */ |
| 38 | + #[Override] |
| 39 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
| 40 | + /** @var ISchemaWrapper $schema */ |
| 41 | + $schema = $schemaClosure(); |
| 42 | + |
| 43 | + if (!$schema->hasTable('richdocuments_wopi')) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + |
| 47 | + $table = $schema->getTable('richdocuments_wopi'); |
| 48 | + |
| 49 | + if (!$table->hasColumn('version')) { |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + $column = $table->getColumn('version'); |
| 54 | + |
| 55 | + if ($column->getType()->getName() === 'string') { |
| 56 | + return null; |
| 57 | + } |
| 58 | + |
| 59 | + $table->changeColumn('version', [ |
| 60 | + 'type' => 'string', |
| 61 | + 'notnull' => false, |
| 62 | + 'length' => 1024, |
| 63 | + 'default' => '0', |
| 64 | + ]); |
| 65 | + |
| 66 | + return $schema; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param IOutput $output |
| 71 | + * @param Closure(): ISchemaWrapper $schemaClosure |
| 72 | + * @param array $options |
| 73 | + */ |
| 74 | + #[Override] |
| 75 | + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { |
| 76 | + } |
| 77 | +} |
0 commit comments