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
57 changes: 28 additions & 29 deletions lib/Migration/Version010200Date20200323141300.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Types;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\SimpleMigrationStep;
Expand Down Expand Up @@ -54,10 +55,8 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
'dropdown' => 'multiple_unique'
];

private const TYPE_BOOLEAN = 'boolean';
private const TYPE_INTEGER = 'integer';
// Adding Type_json, that is recommended in DBAL
private const TYPE_JSON = 'json';
private const TYPE_STRING = 'string';

/**
* @param IDBConnection $connection
Expand All @@ -81,43 +80,43 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op

if (!$schema->hasTable('forms_v2_forms')) {
$table = $schema->createTable('forms_v2_forms');
$table->addColumn('id', self::TYPE_INTEGER, [
$table->addColumn('id', Types::INTEGER, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('hash', self::TYPE_STRING, [
$table->addColumn('hash', Types::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('title', self::TYPE_STRING, [
$table->addColumn('title', Types::STRING, [
'notnull' => true,
'length' => 256,
]);
$table->addColumn('description', self::TYPE_STRING, [
$table->addColumn('description', Types::STRING, [
'notnull' => false,
'length' => 8192,
]);
$table->addColumn('owner_id', self::TYPE_STRING, [
$table->addColumn('owner_id', Types::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('access_json', self::TYPE_JSON, [
'notnull' => false,
]);
$table->addColumn('created', self::TYPE_INTEGER, [
$table->addColumn('created', Types::INTEGER, [
'notnull' => false,
'comment' => 'unix-timestamp',
]);
$table->addColumn('expires', self::TYPE_INTEGER, [
$table->addColumn('expires', Types::INTEGER, [
'notnull' => false,
'default' => 0,
'comment' => 'unix-timestamp',
]);
$table->addColumn('is_anonymous', self::TYPE_BOOLEAN, [
$table->addColumn('is_anonymous', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
]);
$table->addColumn('submit_once', self::TYPE_BOOLEAN, [
$table->addColumn('submit_once', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
]);
Expand All @@ -127,26 +126,26 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op

if (!$schema->hasTable('forms_v2_questions')) {
$table = $schema->createTable('forms_v2_questions');
$table->addColumn('id', self::TYPE_INTEGER, [
$table->addColumn('id', Types::INTEGER, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('form_id', self::TYPE_INTEGER, [
$table->addColumn('form_id', Types::INTEGER, [
'notnull' => true,
]);
$table->addColumn('order', self::TYPE_INTEGER, [
$table->addColumn('order', Types::INTEGER, [
'notnull' => true,
'default' => 1,
]);
$table->addColumn('type', self::TYPE_STRING, [
$table->addColumn('type', Types::STRING, [
'notnull' => true,
'length' => 256,
]);
$table->addColumn('mandatory', self::TYPE_BOOLEAN, [
$table->addColumn('mandatory', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
]);
$table->addColumn('text', self::TYPE_STRING, [
$table->addColumn('text', Types::STRING, [
'notnull' => true,
'length' => 2048,
]);
Expand All @@ -155,14 +154,14 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op

if (!$schema->hasTable('forms_v2_options')) {
$table = $schema->createTable('forms_v2_options');
$table->addColumn('id', self::TYPE_INTEGER, [
$table->addColumn('id', Types::INTEGER, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('question_id', self::TYPE_INTEGER, [
$table->addColumn('question_id', Types::INTEGER, [
'notnull' => true,
]);
$table->addColumn('text', self::TYPE_STRING, [
$table->addColumn('text', Types::STRING, [
'notnull' => true,
'length' => 1024,
]);
Expand All @@ -171,18 +170,18 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op

if (!$schema->hasTable('forms_v2_submissions')) {
$table = $schema->createTable('forms_v2_submissions');
$table->addColumn('id', self::TYPE_INTEGER, [
$table->addColumn('id', Types::INTEGER, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('form_id', self::TYPE_INTEGER, [
$table->addColumn('form_id', Types::INTEGER, [
'notnull' => true,
]);
$table->addColumn('user_id', self::TYPE_STRING, [
$table->addColumn('user_id', Types::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('timestamp', self::TYPE_INTEGER, [
$table->addColumn('timestamp', Types::INTEGER, [
'notnull' => false,
'comment' => 'unix-timestamp',
]);
Expand All @@ -191,17 +190,17 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op

if (!$schema->hasTable('forms_v2_answers')) {
$table = $schema->createTable('forms_v2_answers');
$table->addColumn('id', self::TYPE_INTEGER, [
$table->addColumn('id', Types::INTEGER, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('submission_id', self::TYPE_INTEGER, [
$table->addColumn('submission_id', Types::INTEGER, [
'notnull' => true,
]);
$table->addColumn('question_id', self::TYPE_INTEGER, [
$table->addColumn('question_id', Types::INTEGER, [
'notnull' => true,
]);
$table->addColumn('text', self::TYPE_STRING, [
$table->addColumn('text', Types::STRING, [
'notnull' => true,
'length' => 4096,
]);
Expand Down
5 changes: 2 additions & 3 deletions lib/Migration/Version020300Date20210406114130.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
Expand All @@ -42,8 +43,6 @@ public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}

private const TYPE_BOOLEAN = 'boolean';

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
Expand All @@ -57,7 +56,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table = $schema->getTable('forms_v2_questions');

if (!$table->hasColumn('is_required')) {
$table->addColumn('is_required', self::TYPE_BOOLEAN, [
$table->addColumn('is_required', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
]);
Expand Down
65 changes: 65 additions & 0 deletions lib/Migration/Version030000Date20220402100057.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Jonas Rittershofer <jotoeri@users.noreply.github.com>
*
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
*
* @license AGPL-3.0-or-later
*
* 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 Doctrine\DBAL\Types\Type;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version030000Date20220402100057 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();

$update_necesssary = false;

// Change Type of Description from string to text. Necessary due to length restrictions.
$column = $schema->getTable('forms_v2_forms')->getColumn('description');
if ($column->getType() === Type::getType(Types::STRING)) {
$column->setType(Type::getType(Types::TEXT));
$update_necesssary = true;
}

// Change Type of Answer-Text from string to text. Necessary due to length restrictions.
$column = $schema->getTable('forms_v2_answers')->getColumn('text');
if ($column->getType() === Type::getType(Types::STRING)) {
$column->setType(Type::getType(Types::TEXT));
$update_necesssary = true;
}

return $update_necesssary ? $schema : null;
}
}