Skip to content

Commit

Permalink
Merge pull request #127 from Raudius/bugfix/script_input_migration_de…
Browse files Browse the repository at this point in the history
…fault

Add default value to `filescript_inputs`.`options` column
  • Loading branch information
Raudius authored Dec 16, 2023
2 parents 9c57105 + 59001e4 commit 34bec99
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Migration/Version020100Date20221126.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table = $schema->getTable('filescript_inputs');
$table->addColumn('options', 'text', [
'notnull' => true,
'default' => '[]'
]);
} else {
$this->logger->error('File scripts (Version020100Date20221126) migration failed, because `filescript_inputs` table does not exist.');
Expand Down
47 changes: 47 additions & 0 deletions lib/Migration/Version030100Date20231215.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace OCA\FilesScripts\Migration;

use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
use Psr\Log\LoggerInterface;

/**
* Ensures script input options has default.
*/
class Version030100Date20231215 extends SimpleMigrationStep {
private LoggerInterface $logger;

public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return ISchemaWrapper
* @throws SchemaException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('filescript_inputs')) {
$table = $schema->getTable('filescript_inputs');
$optionsCol = $table->getColumn('options');

$optionsDefault = $optionsCol->getDefault();
if ($optionsDefault === null) {
$this->logger->info("Column `options` in `filescript_inputs` has no default, setting it now.");
$optionsCol->setDefault('[]');
}
} else {
$this->logger->error('File scripts (Version030100Date20231215) migration failed, because `filescript_inputs` table does not exist.');
}
return $schema;
}
}

0 comments on commit 34bec99

Please sign in to comment.