Skip to content

Commit

Permalink
make the column definition not dynamic to avoid runtime problems duri…
Browse files Browse the repository at this point in the history
…ng web update paths

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Jan 5, 2024
1 parent e3e1875 commit eb15c7f
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions lib/Migration/Version000700Date20230916000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,39 @@
namespace OCA\Tables\Migration;

use Closure;
use OCA\Tables\Helper\ColumnsHelper;
use OCP\DB\Exception;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class Version000700Date20230916000000 extends SimpleMigrationStep {

/**
* this is a copy from the definition set in OCA\Tables\Helper\ColumnsHelper
* this has to be in sync! but the definition can not be used directly
* because it might cause problems on auto web updates
* (class might not be loaded if it gets replaced during the runtime)
*/
private array $columns = [
[
'name' => 'text',
'db_type' => Types::TEXT,
],
[
'name' => 'number',
'db_type' => Types::FLOAT,
],
[
'name' => 'datetime',
'db_type' => Types::TEXT,
],
[
'name' => 'selection',
'db_type' => Types::TEXT,
],
];

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
Expand All @@ -32,13 +53,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

$this->createRowSleevesTable($schema);

try {
$columnsHelper = Server::get(ColumnsHelper::class);
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
throw new Exception('Could not fetch columns helper which is needed to setup all the tables.');
}

$rowTypeSchema = $columnsHelper->get(['name', 'db_type']);
$rowTypeSchema = $this->columns;

foreach ($rowTypeSchema as $colType) {
$this->createRowValueTable($schema, $colType['name'], $colType['db_type']);
Expand Down

0 comments on commit eb15c7f

Please sign in to comment.