Skip to content

Commit a1fde9f

Browse files
author
lafricain79
committed
refactor: move schema change to a new migration file
1 parent cabf5f6 commit a1fde9f

2 files changed

Lines changed: 65 additions & 12 deletions

File tree

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,60 @@
11
<?php
2+
23
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-License-Identifier: AGPL-3.0-or-later
68
*/
9+
710
namespace OCA\Forms\Migration;
11+
812
use Closure;
913
use OCP\DB\ISchemaWrapper;
1014
use OCP\DB\Types;
15+
use OCP\IDBConnection;
1116
use OCP\Migration\IOutput;
1217
use OCP\Migration\SimpleMigrationStep;
18+
1319
class Version050300Date20250914000000 extends SimpleMigrationStep {
20+
21+
public function __construct(
22+
protected IDBConnection $db,
23+
) {
24+
}
25+
26+
/**
27+
* @param IOutput $output
28+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
29+
* @param array $options
30+
* @return null|ISchemaWrapper
31+
*/
1432
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
1533
/** @var ISchemaWrapper $schema */
1634
$schema = $schemaClosure();
17-
$table = $schema->getTable('forms_v2_forms');
18-
if (!$table->hasColumn('max_submissions')) {
19-
$table->addColumn('max_submissions', Types::INTEGER, [
20-
'notnull' => false,
21-
'default' => null,
22-
'comment' => 'Maximum number of submissions, null means unlimited',
23-
]);
24-
}
25-
$tableOptions = $schema->getTable('forms_v2_options');
26-
if (!$tableOptions->hasColumn('option_type')) {
27-
$tableOptions->addColumn('option_type', Types::STRING, [
35+
$table = $schema->getTable('forms_v2_options');
36+
37+
if (!$table->hascolumn('option_type')) {
38+
$table->addColumn('option_type', Types::STRING, [
2839
'notnull' => false,
2940
'default' => null,
30-
'length' => 64,
3141
]);
3242
}
43+
3344
return $schema;
3445
}
46+
47+
/**
48+
* @param IOutput $output
49+
* @param Closure(): ISchemaWrapper $schemaClosure
50+
* @param array $options
51+
*/
52+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
53+
$qbUpdate = $this->db->getQueryBuilder();
54+
55+
$qbUpdate->update('forms_v2_options')
56+
->set('option_type', $qbUpdate->createNamedParameter('choice'))
57+
->where($qbUpdate->expr()->isNull('option_type'))
58+
->executeStatement();
59+
}
3560
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OCA\Forms\Migration;
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 Version050300Date20260303000000 extends SimpleMigrationStep {
14+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
15+
/** @var ISchemaWrapper $schema */
16+
$schema = $schemaClosure();
17+
$table = $schema->getTable('forms_v2_forms');
18+
if (!$table->hasColumn('max_submissions')) {
19+
$table->addColumn('max_submissions', Types::INTEGER, [
20+
'notnull' => false,
21+
'default' => null,
22+
'comment' => 'Maximum number of submissions, null means unlimited',
23+
]);
24+
}
25+
26+
return $schema;
27+
}
28+
}

0 commit comments

Comments
 (0)