From 3dda242ef9065f54478dd2f33ae0570448493941 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 9 Jul 2024 18:42:10 +0200 Subject: [PATCH] add migration step to remove old tables Signed-off-by: Julien Veyssier --- appinfo/info.xml | 2 +- .../Version020000Date20240709175759.php | 107 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 lib/Migration/Version020000Date20240709175759.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 72ba9a16..fe19a2df 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -56,7 +56,7 @@ Known providers: * [OpenAi/LocalAI integration](https://apps.nextcloud.com/apps/integration_openai) * [Local Whisper Speech-To-Text](https://apps.nextcloud.com/apps/stt_whisper) ]]> - 2.0.0 + 2.0.1 agpl Julien Veyssier Assistant diff --git a/lib/Migration/Version020000Date20240709175759.php b/lib/Migration/Version020000Date20240709175759.php new file mode 100644 index 00000000..072a5e39 --- /dev/null +++ b/lib/Migration/Version020000Date20240709175759.php @@ -0,0 +1,107 @@ + +// SPDX-License-Identifier: AGPL-3.0-or-later + +declare(strict_types=1); + +namespace OCA\Assistant\Migration; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version020000Date20240709175759 extends SimpleMigrationStep { + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return void + */ + public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + } + + /** + * @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) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + $schemaChanged = false; + + if ($schema->hasTable('assistant_i_files')) { + $table = $schema->getTable('assistant_i_files'); + if ($table->hasIndex('assistant_gen_id')) { + $table->dropIndex('assistant_gen_id'); + } + $schema->dropTable('assistant_i_files'); + $schemaChanged = true; + } + + if ($schema->hasTable('assistant_i_gens')) { + $table = $schema->getTable('assistant_i_gens'); + if ($table->hasIndex('assistant_i_gens_id')) { + $table->dropIndex('assistant_i_gens_id'); + } + $schema->dropTable('assistant_i_gens'); + $schemaChanged = true; + } + + if ($schema->hasTable('assistant_stale_gens')) { + $table = $schema->getTable('assistant_stale_gens'); + if ($table->hasIndex('assistant_i_stale_gens_id')) { + $table->dropIndex('assistant_i_stale_gens_id'); + } + $schema->dropTable('assistant_stale_gens'); + $schemaChanged = true; + } + + if ($schema->hasTable('assistant_i_prompts')) { + $table = $schema->getTable('assistant_i_prompts'); + if ($table->hasIndex('assistant_i_prompt_uid')) { + $table->dropIndex('assistant_i_prompt_uid'); + } + $schema->dropTable('assistant_i_prompts'); + $schemaChanged = true; + } + + if ($schema->hasTable('assistant_t_prompts')) { + $table = $schema->getTable('assistant_t_prompts'); + if ($table->hasIndex('assistant_t_prompts_uid')) { + $table->dropIndex('assistant_t_prompts_uid'); + } + if ($table->hasIndex('assistant_t_prompts_uid_ts')) { + $table->dropIndex('assistant_t_prompts_uid_ts'); + } + $schema->dropTable('assistant_t_prompts'); + $schemaChanged = true; + } + + if ($schema->hasTable('assistant_meta_tasks')) { + $table = $schema->getTable('assistant_meta_tasks'); + if ($table->hasIndex('assistant_meta_task_uid')) { + $table->dropIndex('assistant_meta_task_uid'); + } + if ($table->hasIndex('assistant_meta_task_id_cat')) { + $table->dropIndex('assistant_meta_task_id_cat'); + } + $schema->dropTable('assistant_meta_tasks'); + $schemaChanged = true; + } + + return $schemaChanged ? $schema : null; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return void + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + } +}