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/lib/Migration/Version35000Date20260928000000.php b/lib/Migration/Version35000Date20260928000000.php new file mode 100644 index 00000000..84b4cb0c --- /dev/null +++ b/lib/Migration/Version35000Date20260928000000.php @@ -0,0 +1,22 @@ + ['id', 'file_id', 'ttl'], + ]; + } +} diff --git a/tests/Unit/Migration/Version35000Date20260928000000Test.php b/tests/Unit/Migration/Version35000Date20260928000000Test.php new file mode 100644 index 00000000..e9c350a4 --- /dev/null +++ b/tests/Unit/Migration/Version35000Date20260928000000Test.php @@ -0,0 +1,74 @@ +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, []); + 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(); + 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()); + } + } + + public static function schemaProvider(): array { + return [ + 'fresh install' => [false], + 'legacy integer columns' => [true], + ]; + } +}