Skip to content

Commit 592b99b

Browse files
committed
Conditional drop of federated_invites table to prevent data loss.
Signed-off-by: Antoon P <antoon.prins@surf.nl>
1 parent bf0e3ba commit 592b99b

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

apps/cloud_federation_api/lib/Migration/Version1018Date20260202110547.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@
1010
namespace OCA\CloudFederationAPI\Migration;
1111

1212
use Closure;
13+
use OCP\AppFramework\Services\IAppConfig;
1314
use OCP\DB\ISchemaWrapper;
15+
use OCP\IDBConnection;
1416
use OCP\Migration\Attributes\DropTable;
1517
use OCP\Migration\IOutput;
1618
use OCP\Migration\SimpleMigrationStep;
1719
use Override;
1820

1921
#[DropTable(table: 'federated_invites', columns: ['id', 'user_id', 'recipient_provider', 'recipient_user_id', 'recipient_name', 'recipient_email', 'token', 'accepted', 'created_at', 'expired_at', 'accepted_at'], description: 'Table is moved out of this app.')]
2022
class Version1018Date20260202110547 extends SimpleMigrationStep {
23+
24+
public function __construct(
25+
private readonly IAppConfig $appConfig,
26+
private readonly IDBConnection $db,
27+
) {
28+
}
29+
2130
/**
31+
* Drops the federated_invites table unless it contains data.
32+
*
2233
* @param IOutput $output
2334
* @param Closure(): ISchemaWrapper $schemaClosure
2435
* @param array $options
@@ -31,8 +42,16 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
3142
$table_name = 'federated_invites';
3243

3344
if ($schema->hasTable($table_name)) {
34-
$schema->dropTable($table_name);
35-
return $schema;
45+
$qb = $this->db->getQueryBuilder();
46+
$qb->select('*')
47+
->from($table_name)
48+
->setMaxResults(1);
49+
$result = $qb->executeQuery();
50+
$hasRows = $result->fetchOne();
51+
if(!$hasRows) {
52+
$schema->dropTable($table_name);
53+
return $schema;
54+
}
3655
}
3756
return null;
3857
}

0 commit comments

Comments
 (0)