Unverified Commit d2effbdb authored by Jonas Rittershofer's avatar Jonas Rittershofer
Browse files

Fix boolean columns nullable


Signed-off-by: default avatarJonas Rittershofer <jotoeri@users.noreply.github.com>
parent f5b2bcaf
......@@ -114,11 +114,11 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
'comment' => 'unix-timestamp',
]);
$table->addColumn('is_anonymous', self::TYPE_BOOLEAN, [
'notnull' => true,
'notnull' => false,
'default' => 0,
]);
$table->addColumn('submit_once', self::TYPE_BOOLEAN, [
'notnull' => true,
'notnull' => false,
'default' => 0,
]);
$table->setPrimaryKey(['id']);
......@@ -143,7 +143,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
'length' => 256,
]);
$table->addColumn('mandatory', self::TYPE_BOOLEAN, [
'notnull' => true,
'notnull' => false,
'default' => 0,
]);
$table->addColumn('text', self::TYPE_STRING, [
......
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Jonas Rittershofer <jotoeri@users.noreply.github.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Forms\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version020300Date20210403214012 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$result = $this->ensureColumnIsNullable($schema, 'forms_v2_forms', 'is_anonymous');
$result |= $this->ensureColumnIsNullable($schema, 'forms_v2_forms', 'submit_once');
$result |= $this->ensureColumnIsNullable($schema, 'forms_v2_questions', 'mandatory');
return $result ? $schema : null;
}
protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
$table = $schema->getTable($tableName);
$column = $table->getColumn($columnName);
if ($column->getNotnull()) {
$column->setNotnull(false);
return true;
}
return false;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment