Skip to content

Commit 611de40

Browse files
committed
Migrate long text columns
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
1 parent 2f5a7e7 commit 611de40

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Jonas Rittershofer <jotoeri@users.noreply.github.com>
6+
*
7+
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
8+
*
9+
* @license AGPL-3.0-or-later
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+
26+
namespace OCA\Forms\Migration;
27+
28+
use Closure;
29+
use Doctrine\DBAL\Types\Type;
30+
use OCP\DB\ISchemaWrapper;
31+
use OCP\DB\Types;
32+
use OCP\Migration\IOutput;
33+
use OCP\Migration\SimpleMigrationStep;
34+
35+
class Version030000Date20220402100057 extends SimpleMigrationStep {
36+
37+
/**
38+
* @param IOutput $output
39+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
40+
* @param array $options
41+
* @return null|ISchemaWrapper
42+
*/
43+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
44+
/** @var ISchemaWrapper $schema */
45+
$schema = $schemaClosure();
46+
47+
$update_necesssary = false;
48+
49+
// Change Type of Description from string to text. Necessary due to length restrictions.
50+
$column = $schema->getTable('forms_v2_forms')->getColumn('description');
51+
if ($column->getType() === Type::getType(Types::STRING)) {
52+
$column->setType(Type::getType(Types::TEXT));
53+
$update_necesssary = true;
54+
}
55+
56+
// Change Type of Answer-Text from string to text. Necessary due to length restrictions.
57+
$column = $schema->getTable('forms_v2_answers')->getColumn('text');
58+
if ($column->getType() === Type::getType(Types::STRING)) {
59+
$column->setType(Type::getType(Types::TEXT));
60+
$update_necesssary = true;
61+
}
62+
63+
return $update_necesssary ? $schema : null;
64+
}
65+
}

0 commit comments

Comments
 (0)