Repository navigation
feat(views): allow views without a table #3075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+1,055
−26
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0027d3
feat(views): allow views without a table and give views a type
remko48 631def2
fix(views): tell standalone views apart from federated views
remko48 2ebf8c7
fix(views): name views without a table by their id
remko48 41f5365
Merge branch 'main' into feat/noid/views-without-table
remko48 4a25495
fix(views): address review on views without a table
remko48 475a169
fix(views): give federated proxy views their own uuid
remko48 2aeada5
Merge remote-tracking branch 'upstream/main' into main-forked
remko48 a5c5e25
Merge branch 'main-forked' into stack/g1-views-without-table
remko48 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Tables\Migration; | ||
|
|
||
| use Closure; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\DB\Types; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
| use Override; | ||
|
|
||
| /** | ||
| * Views get a type (table, grid). table_id is already nullable for federated views | ||
| * (Version2203Date20260821000000), so a view without a table needs no schema change. | ||
| */ | ||
| class Version2400Date20261012000000 extends SimpleMigrationStep { | ||
| #[Override] | ||
| public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
|
|
||
| if ($schema->hasTable('tables_views')) { | ||
| $table = $schema->getTable('tables_views'); | ||
| if (!$table->hasColumn('type')) { | ||
| $table->addColumn('type', Types::STRING, [ | ||
| 'notnull' => true, | ||
| 'default' => 'table', | ||
| 'length' => 16, | ||
| ]); | ||
| } | ||
| } | ||
|
|
||
| return $schema; | ||
| } | ||
| } |
This file contains hidden or 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,91 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Tables\Migration; | ||
|
|
||
| use Closure; | ||
| use OCA\Tables\Vendor\Symfony\Component\Uid\Uuid; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
| use OCP\IDBConnection; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
| use Override; | ||
|
|
||
| /** | ||
| * A view's uuid is unique on its own, also for views without a table: the index on | ||
| * (table_id, uuid) does not hold when table_id is null, so it gives way to an index on uuid alone. | ||
| * Imports and federated proxy views used to keep the uuid of their source, so views that share | ||
| * one get a fresh uuid first; a local view keeps its own. | ||
| */ | ||
| class Version2400Date20261013000000 extends SimpleMigrationStep { | ||
| public function __construct( | ||
| private readonly IDBConnection $connection, | ||
| ) { | ||
| } | ||
|
|
||
| #[Override] | ||
| public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
| $select = $this->connection->getQueryBuilder(); | ||
| $select->select('id', 'uuid', 'external_id') | ||
| ->from('tables_views') | ||
| ->where($select->expr()->isNotNull('uuid')) | ||
| ->orderBy('id', 'ASC'); | ||
| $result = $select->executeQuery(); | ||
| $rows = []; | ||
| while ($row = $result->fetchAssociative()) { | ||
| $rows[] = $row; | ||
| } | ||
| $result->closeCursor(); | ||
|
|
||
| // A local view keeps its uuid; a federated proxy that copied it from its source gets a fresh one | ||
| usort($rows, static fn (array $a, array $b): int => [$a['external_id'] !== null, (int)$a['id']] <=> [$b['external_id'] !== null, (int)$b['id']]); | ||
| $seen = []; | ||
| $duplicateIds = []; | ||
| foreach ($rows as $row) { | ||
| if (isset($seen[$row['uuid']])) { | ||
| $duplicateIds[] = (int)$row['id']; | ||
| continue; | ||
| } | ||
| $seen[$row['uuid']] = true; | ||
| } | ||
|
|
||
| $update = $this->connection->getQueryBuilder(); | ||
| $update->update('tables_views') | ||
| ->set('uuid', $update->createParameter('uuid')) | ||
| ->where($update->expr()->eq('id', $update->createParameter('id'))); | ||
| foreach ($duplicateIds as $id) { | ||
| $update->setParameter('uuid', Uuid::v7()->toRfc4122()); | ||
| $update->setParameter('id', $id, IQueryBuilder::PARAM_INT); | ||
| $update->executeStatement(); | ||
| } | ||
| if ($duplicateIds !== []) { | ||
| $output->info(count($duplicateIds) . ' views got a fresh uuid because another view already used theirs'); | ||
| } | ||
| } | ||
|
|
||
| #[Override] | ||
| public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
|
|
||
| if ($schema->hasTable('tables_views')) { | ||
| $table = $schema->getTable('tables_views'); | ||
| if (!$table->hasIndex('tables_views_uuid_only_uniq')) { | ||
| $table->addUniqueIndex(['uuid'], 'tables_views_uuid_only_uniq'); | ||
| } | ||
| // The uuid-only index covers the old (table_id, uuid) one | ||
| if ($table->hasIndex('tables_views_uuid_uniq')) { | ||
| $table->dropIndex('tables_views_uuid_uniq'); | ||
| } | ||
| } | ||
|
|
||
| return $schema; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.