Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Migration/Version0001Date20191105000001.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion lib/Migration/Version1000Date20220201111525.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions lib/Migration/Version35000Date20260928000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\FilesLock\Migration;

use OCP\Migration\BigIntMigration;

class Version35000Date20260928000000 extends BigIntMigration {

#[\Override]
protected function getColumnsByTable(): array {
return [
'files_lock' => ['id', 'file_id', 'ttl'],
];
}
}
74 changes: 74 additions & 0 deletions tests/Unit/Migration/Version35000Date20260928000000Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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 OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use PHPUnit\Framework\TestCase;

class Version35000Date20260928000000Test extends TestCase {

/**
* @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);
$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],
];
}
}
Loading