Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/Migration/Version050300Date20250914000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$schema = $schemaClosure();
$table = $schema->getTable('forms_v2_options');

if (!$table->hascolumn('option_type')) {
if (!$table->hasColumn('option_type')) {
$table->addColumn('option_type', Types::STRING, [
'notnull' => false,
'length' => 255,
'default' => null,
]);
}
Expand All @@ -50,6 +51,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->getTable('forms_v2_options')->hasColumn('option_type')) {
return;
}

$qbUpdate = $this->db->getQueryBuilder();

$qbUpdate->update('forms_v2_options')
Expand Down
36 changes: 28 additions & 8 deletions lib/Migration/Version050300Date20260716000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
Expand All @@ -20,6 +21,11 @@
* rows that were stored without a type. Options created through the API
* without an explicit optionType previously kept a null type, which the
* frontend does not render.
*
* The column is normally created by Version050300Date20250914000000. That
* migration being recorded in oc_migrations is not a guarantee that its DDL
* was applied, so this step recreates the column when it is missing instead
* of failing the whole upgrade.
*/
class Version050300Date20260716000000 extends SimpleMigrationStep {

Expand All @@ -38,17 +44,25 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$table = $schema->getTable('forms_v2_options');
$changed = false;

if ($table->hasColumn('option_type')) {
$column = $table->getColumn('option_type');
if ($column->getDefault() === null) {
$column->setDefault('choice');
$changed = true;
}
if (!$table->hasColumn('option_type')) {
$table->addColumn('option_type', Types::STRING, [
'notnull' => false,
'length' => 255,
'default' => 'choice',
]);

return $schema;
}

$column = $table->getColumn('option_type');
if ($column->getDefault() === null) {
$column->setDefault('choice');

return $schema;
}

return $changed ? $schema : null;
return null;
}

/**
Expand All @@ -57,6 +71,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->getTable('forms_v2_options')->hasColumn('option_type')) {
return;
}

$qbUpdate = $this->db->getQueryBuilder();

$qbUpdate->update('forms_v2_options')
Expand Down
Loading