From d63c17d3093564dedd91351cef5960fb217e24f7 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Tue, 16 Jun 2026 17:19:40 -0300 Subject: [PATCH] fix: enforce non-null user element node id Delete corrupted rows with NULL node_id before enforcing the database constraint for future writes. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../Version18003Date20260616000000.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lib/Migration/Version18003Date20260616000000.php diff --git a/lib/Migration/Version18003Date20260616000000.php b/lib/Migration/Version18003Date20260616000000.php new file mode 100644 index 0000000000..658f5c143b --- /dev/null +++ b/lib/Migration/Version18003Date20260616000000.php @@ -0,0 +1,63 @@ +connection->getQueryBuilder(); + $qb->delete('libresign_user_element') + ->where($qb->expr()->isNull('node_id')); + $deleted = $qb->executeStatement(); + if ($deleted > 0) { + $output->warning(sprintf( + 'Deleted %d row(s) from libresign_user_element with NULL node_id (corrupted rows with no associated file).', + $deleted, + )); + } + } + + /** + * @param IOutput $output + * @param Closure(): ISchemaWrapper $schemaClosure + * @param array $options + * @return ISchemaWrapper|null + */ + #[\Override] + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('libresign_user_element'); + $column = $table->getColumn('node_id'); + if ($column->getNotnull()) { + return null; + } + + $column->setNotnull(true); + return $schema; + } +}