-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from Raudius/bugfix/script_input_migration_de…
…fault Add default value to `filescript_inputs`.`options` column
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |