Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/Migration/Version1Date20250828120000.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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) {
Expand All @@ -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
10 changes: 9 additions & 1 deletion lib/Migration/Version1Date20250902140000.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Nit (non-blocking) — this inline JSON-type check duplicates the canUseBtreeIndex() helper added in Version1Date20250828120000.php. Since each Nextcloud migration is conventionally self-contained, this is fine to leave as-is, but if a third migration ever needs the same guard, consider lifting the check into a small shared helper (e.g. a trait under lib/Migration/) so the JSON-type rule lives in one place. Not blocking the merge.

) {
$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');
}
Expand Down
Loading