From 59001e401bdd2b1fa5c8b077c219ab0ba45bec5d Mon Sep 17 00:00:00 2001 From: Raul Ferreira Date: Sat, 16 Dec 2023 19:28:19 +0100 Subject: [PATCH] add default value "[]" to `filescript_inputs`.`options` column Signed-off-by: Raul Ferreira --- lib/Migration/Version020100Date20221126.php | 1 + lib/Migration/Version030100Date20231215.php | 47 +++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 lib/Migration/Version030100Date20231215.php diff --git a/lib/Migration/Version020100Date20221126.php b/lib/Migration/Version020100Date20221126.php index c8d716d..6a6d01c 100755 --- a/lib/Migration/Version020100Date20221126.php +++ b/lib/Migration/Version020100Date20221126.php @@ -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.'); diff --git a/lib/Migration/Version030100Date20231215.php b/lib/Migration/Version030100Date20231215.php new file mode 100755 index 0000000..1bbbe9f --- /dev/null +++ b/lib/Migration/Version030100Date20231215.php @@ -0,0 +1,47 @@ +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; + } +}