diff --git a/lib/Migration/Version1Date20250828120000.php b/lib/Migration/Version1Date20250828120000.php index 6d131dc0a8..d5c772d56a 100644 --- a/lib/Migration/Version1Date20250828120000.php +++ b/lib/Migration/Version1Date20250828120000.php @@ -24,6 +24,7 @@ use Closure; use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -74,6 +75,11 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]; foreach ($singleIndexes as $column => $indexName) { + if ($table->hasColumn($column) && $this->canUseBtreeIndex($table, $column) === false) { + $output->info("Skipped index {$indexName} on JSON column {$column}"); + continue; + } + if ($table->hasColumn($column) && !$table->hasIndex($indexName)) { $table->addIndex([$column], $indexName); $output->info("Added index {$indexName} on column {$column}"); @@ -121,6 +127,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $allColumnsExist = false; break; } + + if ($this->canUseBtreeIndex($table, $column) === false) { + $allColumnsExist = false; + $output->info("Skipped composite index {$indexName} because {$column} is a JSON column"); + break; + } } if ($allColumnsExist) { @@ -139,4 +151,21 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt }//end changeSchema() + /** + * Checks whether a column can be used in a regular btree index. + * + * JSON columns do not have a default btree operator class in PostgreSQL and + * also need special handling on other supported databases. + * + * @param mixed $table The table definition + * @param string $column The column name + * + * @return bool + */ + private function canUseBtreeIndex($table, string $column): bool + { + return $table->getColumn($column)->getType()->getName() !== Types::JSON; + }//end canUseBtreeIndex() + + }//end class diff --git a/lib/Migration/Version1Date20250902140000.php b/lib/Migration/Version1Date20250902140000.php index 96a8ca5772..813e46223d 100644 --- a/lib/Migration/Version1Date20250902140000.php +++ b/lib/Migration/Version1Date20250902140000.php @@ -6,6 +6,7 @@ use Closure; use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -86,7 +87,14 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt } // Soft delete filtering - if (!$table->hasIndex('objects_deleted_idx')) { + if ( + $table->hasColumn('deleted') + && $table->getColumn('deleted')->getType()->getName() === Types::JSON + ) { + $output->info('Skipped index objects_deleted_idx because deleted is a JSON column'); + } elseif ($table->hasColumn('deleted') === false) { + $output->info('Skipped index objects_deleted_idx because deleted column does not exist'); + } elseif (!$table->hasIndex('objects_deleted_idx')) { $table->addIndex(['deleted'], 'objects_deleted_idx'); $output->info('Added index objects_deleted_idx for soft delete filtering'); }