From 070e8ddc5c51eabca8186e0d9e8a3daa2e144c65 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Mon, 28 Sep 2026 09:32:35 +0200 Subject: [PATCH 1/3] fix: widen lock identifiers and durations to bigint Assisted-by: Codex:GPT-6 Signed-off-by: Julius Knorr --- .../Version35000Date20260928000000.php | 21 +++++++ .../Version35000Date20260928000000Test.php | 55 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 lib/Migration/Version35000Date20260928000000.php create mode 100644 tests/Unit/Migration/Version35000Date20260928000000Test.php diff --git a/lib/Migration/Version35000Date20260928000000.php b/lib/Migration/Version35000Date20260928000000.php new file mode 100644 index 00000000..f0536b78 --- /dev/null +++ b/lib/Migration/Version35000Date20260928000000.php @@ -0,0 +1,21 @@ + ['id', 'file_id', 'ttl'], + ]; + } +} diff --git a/tests/Unit/Migration/Version35000Date20260928000000Test.php b/tests/Unit/Migration/Version35000Date20260928000000Test.php new file mode 100644 index 00000000..baf9ff25 --- /dev/null +++ b/tests/Unit/Migration/Version35000Date20260928000000Test.php @@ -0,0 +1,55 @@ +createMock(ISchemaWrapper::class); + $schema->method('hasTable')->with('files_lock')->willReturn(false); + $schema->method('createTable')->with('files_lock')->willReturn($table); + $schema->method('getTable')->with('files_lock')->willReturn($table); + $output = $this->createMock(IOutput::class); + $schemaClosure = static fn () => $schema; + + (new Version0001Date20191105000001($this->createMock(IDBConnection::class)))->changeSchema($output, $schemaClosure, []); + (new Version1000Date20220201111525())->changeSchema($output, $schemaClosure, []); + (new Version1000Date20220430180808())->changeSchema($output, $schemaClosure, []); + $before = clone $table->getWrappedTable(); + + $migration = new Version35000Date20260928000000(); + for ($run = 0; $run < 2; $run++) { + self::assertSame($schema, $migration->changeSchema($output, $schemaClosure, [])); + foreach ($table->getWrappedTable()->getColumns() as $name => $column) { + $expected = $before->getColumn($name)->toArray(); + if (in_array($name, ['id', 'file_id', 'ttl'], true)) { + self::assertSame(Types::BIGINT, $column->getType()->getName()); + $expected['type'] = $column->getType(); + $expected['length'] = 20; + } + self::assertEquals($expected, $column->toArray(), $name); + } + self::assertEquals($before->getIndexes(), $table->getWrappedTable()->getIndexes()); + } + } +} From 9ca97f1896cc50acdd3c852348624002b8e282a2 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Mon, 28 Sep 2026 09:41:30 +0200 Subject: [PATCH 2/3] fix: satisfy migration static analysis and coding style Assisted-by: Codex:GPT-6 Signed-off-by: Julius Knorr --- lib/Migration/Version35000Date20260928000000.php | 1 + tests/Unit/Migration/Version35000Date20260928000000Test.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Migration/Version35000Date20260928000000.php b/lib/Migration/Version35000Date20260928000000.php index f0536b78..84b4cb0c 100644 --- a/lib/Migration/Version35000Date20260928000000.php +++ b/lib/Migration/Version35000Date20260928000000.php @@ -13,6 +13,7 @@ class Version35000Date20260928000000 extends BigIntMigration { + #[\Override] protected function getColumnsByTable(): array { return [ 'files_lock' => ['id', 'file_id', 'ttl'], diff --git a/tests/Unit/Migration/Version35000Date20260928000000Test.php b/tests/Unit/Migration/Version35000Date20260928000000Test.php index baf9ff25..796a4fe5 100644 --- a/tests/Unit/Migration/Version35000Date20260928000000Test.php +++ b/tests/Unit/Migration/Version35000Date20260928000000Test.php @@ -10,11 +10,11 @@ namespace OCA\FilesLock\Tests\Unit\Migration; use Doctrine\DBAL\Schema\Table as DBALTable; +use OC\DB\Schema\Table; use OCA\FilesLock\Migration\Version0001Date20191105000001; use OCA\FilesLock\Migration\Version1000Date20220201111525; use OCA\FilesLock\Migration\Version1000Date20220430180808; use OCA\FilesLock\Migration\Version35000Date20260928000000; -use OC\DB\Schema\Table; use OCP\DB\ISchemaWrapper; use OCP\DB\Types; use OCP\IDBConnection; From 32a86eaac709a156dc43faf53495a193a2e0e2b3 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Mon, 28 Sep 2026 19:37:47 +0200 Subject: [PATCH 3/3] fix: use bigint in initial lock migrations Assisted-by: Codex:GPT-6 Signed-off-by: Julius Knorr --- .../Version0001Date20191105000001.php | 8 +++---- .../Version1000Date20220201111525.php | 3 ++- .../Version35000Date20260928000000Test.php | 21 ++++++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/Migration/Version0001Date20191105000001.php b/lib/Migration/Version0001Date20191105000001.php index 38e5b037..5faf81fd 100644 --- a/lib/Migration/Version0001Date20191105000001.php +++ b/lib/Migration/Version0001Date20191105000001.php @@ -52,12 +52,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table = $schema->createTable('files_lock'); $table->addColumn( - 'id', 'integer', + 'id', 'bigint', [ 'autoincrement' => true, 'unsigned' => true, 'notnull' => true, - 'length' => 11 + 'length' => 20 ] ); $table->addColumn( @@ -68,11 +68,11 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ] ); $table->addColumn( - 'file_id', 'integer', + 'file_id', 'bigint', [ 'notnull' => true, 'unsigned' => true, - 'length' => 11, + 'length' => 20, ] ); $table->addColumn( diff --git a/lib/Migration/Version1000Date20220201111525.php b/lib/Migration/Version1000Date20220201111525.php index c026c84e..064b059a 100644 --- a/lib/Migration/Version1000Date20220201111525.php +++ b/lib/Migration/Version1000Date20220201111525.php @@ -47,9 +47,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if (!$table->hasColumn('ttl')) { $table->addColumn( - 'ttl', Types::INTEGER, + 'ttl', Types::BIGINT, [ 'default' => 0, + 'length' => 20, ] ); $hasSchemaChanges = true; diff --git a/tests/Unit/Migration/Version35000Date20260928000000Test.php b/tests/Unit/Migration/Version35000Date20260928000000Test.php index 796a4fe5..e9c350a4 100644 --- a/tests/Unit/Migration/Version35000Date20260928000000Test.php +++ b/tests/Unit/Migration/Version35000Date20260928000000Test.php @@ -23,7 +23,10 @@ class Version35000Date20260928000000Test extends TestCase { - public function testMigrationPreservesSchemaAndCanRunAgain(): void { + /** + * @dataProvider schemaProvider + */ + public function testMigrationPreservesSchemaAndCanRunAgain(bool $legacySchema): void { $table = new Table(new DBALTable('files_lock')); $schema = $this->createMock(ISchemaWrapper::class); $schema->method('hasTable')->with('files_lock')->willReturn(false); @@ -35,6 +38,15 @@ public function testMigrationPreservesSchemaAndCanRunAgain(): void { (new Version0001Date20191105000001($this->createMock(IDBConnection::class)))->changeSchema($output, $schemaClosure, []); (new Version1000Date20220201111525())->changeSchema($output, $schemaClosure, []); (new Version1000Date20220430180808())->changeSchema($output, $schemaClosure, []); + foreach (['id', 'file_id', 'ttl'] as $name) { + $column = $table->getColumn($name); + self::assertSame(Types::BIGINT, $column->getType()->getName()); + self::assertSame(20, $column->getLength()); + if ($legacySchema) { + $column->setType(Types::INTEGER); + $column->setLength($name === 'ttl' ? null : 11); + } + } $before = clone $table->getWrappedTable(); $migration = new Version35000Date20260928000000(); @@ -52,4 +64,11 @@ public function testMigrationPreservesSchemaAndCanRunAgain(): void { self::assertEquals($before->getIndexes(), $table->getWrappedTable()->getIndexes()); } } + + public static function schemaProvider(): array { + return [ + 'fresh install' => [false], + 'legacy integer columns' => [true], + ]; + } }