From 260453fc194afda2b5e0ed7478ed1fab351c0345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Alfonso=20Pym=20Mej=C3=ADa?= Date: Thu, 22 Oct 2026 02:11:37 -0600 Subject: [PATCH 1/2] fix(core): skip existing columns and indexes in re-run migrations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Mario Alfonso Pym Mejía --- .../Version30000Date20240815080800.php | 4 +- .../Version31000Date20240814184402.php | 24 +++++-- .../Version33000Date20251023120529.php | 4 +- .../Version30000Date20240815080800Test.php | 47 +++++++++++++ .../Version31000Date20240814184402Test.php | 67 +++++++++++++++++++ .../Version33000Date20251023120529Test.php | 58 ++++++++++++++++ 6 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 tests/Core/Migrations/Version30000Date20240815080800Test.php create mode 100644 tests/Core/Migrations/Version31000Date20240814184402Test.php create mode 100644 tests/Core/Migrations/Version33000Date20251023120529Test.php diff --git a/core/Migrations/Version30000Date20240815080800.php b/core/Migrations/Version30000Date20240815080800.php index 5212467ece04e..192b8e3e0376c 100644 --- a/core/Migrations/Version30000Date20240815080800.php +++ b/core/Migrations/Version30000Date20240815080800.php @@ -24,7 +24,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $schema = $schemaClosure(); $table = $schema->getTable('webauthn'); - $table->addColumn('user_verification', Types::BOOLEAN, ['notnull' => false, 'default' => false]); + if (!$table->hasColumn('user_verification')) { + $table->addColumn('user_verification', Types::BOOLEAN, ['notnull' => false, 'default' => false]); + } return $schema; } } diff --git a/core/Migrations/Version31000Date20240814184402.php b/core/Migrations/Version31000Date20240814184402.php index 14b32a704beda..0b8e5276e0a18 100644 --- a/core/Migrations/Version31000Date20240814184402.php +++ b/core/Migrations/Version31000Date20240814184402.php @@ -35,10 +35,18 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $schema = $schemaClosure(); $table = $schema->getTable('preferences'); - $table->addColumn('lazy', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'length' => 1, 'unsigned' => true]); - $table->addColumn('type', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'unsigned' => true]); - $table->addColumn('flags', Types::INTEGER, ['notnull' => true, 'default' => 0, 'unsigned' => true]); - $table->addColumn('indexed', Types::STRING, ['notnull' => false, 'default' => '', 'length' => 64]); + if (!$table->hasColumn('lazy')) { + $table->addColumn('lazy', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'length' => 1, 'unsigned' => true]); + } + if (!$table->hasColumn('type')) { + $table->addColumn('type', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'unsigned' => true]); + } + if (!$table->hasColumn('flags')) { + $table->addColumn('flags', Types::INTEGER, ['notnull' => true, 'default' => 0, 'unsigned' => true]); + } + if (!$table->hasColumn('indexed')) { + $table->addColumn('indexed', Types::STRING, ['notnull' => false, 'default' => '', 'length' => 64]); + } // removing this index from Version13000Date20170718121200 // $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); @@ -46,8 +54,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->dropIndex('preferences_app_key'); } - $table->addIndex(['userid', 'lazy'], 'prefs_uid_lazy_i'); - $table->addIndex(['appid', 'configkey', 'indexed', 'flags'], 'prefs_app_key_ind_fl_i'); + if (!$table->hasIndex('prefs_uid_lazy_i')) { + $table->addIndex(['userid', 'lazy'], 'prefs_uid_lazy_i'); + } + if (!$table->hasIndex('prefs_app_key_ind_fl_i')) { + $table->addIndex(['appid', 'configkey', 'indexed', 'flags'], 'prefs_app_key_ind_fl_i'); + } return $schema; } diff --git a/core/Migrations/Version33000Date20251023120529.php b/core/Migrations/Version33000Date20251023120529.php index 5c04b3942084d..87998e3d6aa02 100644 --- a/core/Migrations/Version33000Date20251023120529.php +++ b/core/Migrations/Version33000Date20251023120529.php @@ -35,7 +35,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('preview_locations')) { $table = $schema->getTable('preview_locations'); - $table->addUniqueIndex(['bucket_name', 'object_store_name'], 'unique_bucket_store'); + if (!$table->hasIndex('unique_bucket_store')) { + $table->addUniqueIndex(['bucket_name', 'object_store_name'], 'unique_bucket_store'); + } } return $schema; diff --git a/tests/Core/Migrations/Version30000Date20240815080800Test.php b/tests/Core/Migrations/Version30000Date20240815080800Test.php new file mode 100644 index 0000000000000..16993b5107772 --- /dev/null +++ b/tests/Core/Migrations/Version30000Date20240815080800Test.php @@ -0,0 +1,47 @@ +createMock(ISchemaWrapper::class); + $schema->method('getTable') + ->with('webauthn') + ->willReturn($table); + + $migration = new Version30000Date20240815080800(); + $this->assertSame($schema, $migration->changeSchema($this->createMock(IOutput::class), fn () => $schema, [])); + } + + public function testChangeSchemaAddsColumn(): void { + $table = new Table(new DBALTable('webauthn')); + + $this->runMigration($table); + + $this->assertTrue($table->hasColumn('user_verification')); + } + + public function testChangeSchemaWithExistingColumn(): void { + $table = new Table(new DBALTable('webauthn')); + $table->addColumn('user_verification', Types::BOOLEAN, ['notnull' => false, 'default' => false]); + + $this->runMigration($table); + + $this->assertCount(1, $table->getColumns()); + } +} diff --git a/tests/Core/Migrations/Version31000Date20240814184402Test.php b/tests/Core/Migrations/Version31000Date20240814184402Test.php new file mode 100644 index 0000000000000..89e1ca59e894a --- /dev/null +++ b/tests/Core/Migrations/Version31000Date20240814184402Test.php @@ -0,0 +1,67 @@ +addColumn('userid', Types::STRING, ['length' => 64]); + $table->addColumn('appid', Types::STRING, ['length' => 32]); + $table->addColumn('configkey', Types::STRING, ['length' => 64]); + return $table; + } + + private function runMigration(Table $table): void { + $schema = $this->createMock(ISchemaWrapper::class); + $schema->method('getTable') + ->with('preferences') + ->willReturn($table); + + $migration = new Version31000Date20240814184402(); + $this->assertSame($schema, $migration->changeSchema($this->createMock(IOutput::class), fn () => $schema, [])); + } + + public function testChangeSchemaAddsColumnsAndIndexes(): void { + $table = $this->createPreferencesTable(); + $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); + + $this->runMigration($table); + + foreach (['lazy', 'type', 'flags', 'indexed'] as $column) { + $this->assertTrue($table->hasColumn($column), "Column $column is missing"); + } + $this->assertFalse($table->hasIndex('preferences_app_key')); + $this->assertSame(['userid', 'lazy'], $table->getIndex('prefs_uid_lazy_i')->getColumns()); + $this->assertSame(['appid', 'configkey', 'indexed', 'flags'], $table->getIndex('prefs_app_key_ind_fl_i')->getColumns()); + } + + public function testChangeSchemaWithExistingColumnsAndIndexes(): void { + $table = $this->createPreferencesTable(); + $table->addColumn('lazy', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'length' => 1, 'unsigned' => true]); + $table->addColumn('type', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'unsigned' => true]); + $table->addColumn('flags', Types::INTEGER, ['notnull' => true, 'default' => 0, 'unsigned' => true]); + $table->addColumn('indexed', Types::STRING, ['notnull' => false, 'default' => '', 'length' => 64]); + $table->addIndex(['userid', 'lazy'], 'prefs_uid_lazy_i'); + $table->addIndex(['appid', 'configkey', 'indexed', 'flags'], 'prefs_app_key_ind_fl_i'); + + $this->runMigration($table); + + $this->assertCount(7, $table->getColumns()); + $this->assertCount(2, $table->getIndexes()); + } +} diff --git a/tests/Core/Migrations/Version33000Date20251023120529Test.php b/tests/Core/Migrations/Version33000Date20251023120529Test.php new file mode 100644 index 0000000000000..20f06531984a1 --- /dev/null +++ b/tests/Core/Migrations/Version33000Date20251023120529Test.php @@ -0,0 +1,58 @@ +addColumn('bucket_name', Types::STRING, ['length' => 40]); + $table->addColumn('object_store_name', Types::STRING, ['length' => 40]); + return $table; + } + + private function runMigration(Table $table): void { + $schema = $this->createMock(ISchemaWrapper::class); + $schema->method('hasTable') + ->with('preview_locations') + ->willReturn(true); + $schema->method('getTable') + ->with('preview_locations') + ->willReturn($table); + + $migration = new Version33000Date20251023120529($this->createMock(IDBConnection::class)); + $this->assertSame($schema, $migration->changeSchema($this->createMock(IOutput::class), fn () => $schema, [])); + } + + public function testChangeSchemaAddsUniqueIndex(): void { + $table = $this->createPreviewLocationsTable(); + + $this->runMigration($table); + + $this->assertTrue($table->getIndex('unique_bucket_store')->isUnique()); + } + + public function testChangeSchemaWithExistingUniqueIndex(): void { + $table = $this->createPreviewLocationsTable(); + $table->addUniqueIndex(['bucket_name', 'object_store_name'], 'unique_bucket_store'); + + $this->runMigration($table); + + $this->assertCount(1, $table->getIndexes()); + } +} From c8c9d08eb9e09d5090f40cdc0c5000ded38957d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Alfonso=20Pym=20Mej=C3=ADa?= Date: Wed, 11 Nov 2026 12:49:16 -0600 Subject: [PATCH 2/2] test(core): drop the migration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Mario Alfonso Pym Mejía --- .../Version30000Date20240815080800Test.php | 47 ------------- .../Version31000Date20240814184402Test.php | 67 ------------------- .../Version33000Date20251023120529Test.php | 58 ---------------- 3 files changed, 172 deletions(-) delete mode 100644 tests/Core/Migrations/Version30000Date20240815080800Test.php delete mode 100644 tests/Core/Migrations/Version31000Date20240814184402Test.php delete mode 100644 tests/Core/Migrations/Version33000Date20251023120529Test.php diff --git a/tests/Core/Migrations/Version30000Date20240815080800Test.php b/tests/Core/Migrations/Version30000Date20240815080800Test.php deleted file mode 100644 index 16993b5107772..0000000000000 --- a/tests/Core/Migrations/Version30000Date20240815080800Test.php +++ /dev/null @@ -1,47 +0,0 @@ -createMock(ISchemaWrapper::class); - $schema->method('getTable') - ->with('webauthn') - ->willReturn($table); - - $migration = new Version30000Date20240815080800(); - $this->assertSame($schema, $migration->changeSchema($this->createMock(IOutput::class), fn () => $schema, [])); - } - - public function testChangeSchemaAddsColumn(): void { - $table = new Table(new DBALTable('webauthn')); - - $this->runMigration($table); - - $this->assertTrue($table->hasColumn('user_verification')); - } - - public function testChangeSchemaWithExistingColumn(): void { - $table = new Table(new DBALTable('webauthn')); - $table->addColumn('user_verification', Types::BOOLEAN, ['notnull' => false, 'default' => false]); - - $this->runMigration($table); - - $this->assertCount(1, $table->getColumns()); - } -} diff --git a/tests/Core/Migrations/Version31000Date20240814184402Test.php b/tests/Core/Migrations/Version31000Date20240814184402Test.php deleted file mode 100644 index 89e1ca59e894a..0000000000000 --- a/tests/Core/Migrations/Version31000Date20240814184402Test.php +++ /dev/null @@ -1,67 +0,0 @@ -addColumn('userid', Types::STRING, ['length' => 64]); - $table->addColumn('appid', Types::STRING, ['length' => 32]); - $table->addColumn('configkey', Types::STRING, ['length' => 64]); - return $table; - } - - private function runMigration(Table $table): void { - $schema = $this->createMock(ISchemaWrapper::class); - $schema->method('getTable') - ->with('preferences') - ->willReturn($table); - - $migration = new Version31000Date20240814184402(); - $this->assertSame($schema, $migration->changeSchema($this->createMock(IOutput::class), fn () => $schema, [])); - } - - public function testChangeSchemaAddsColumnsAndIndexes(): void { - $table = $this->createPreferencesTable(); - $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); - - $this->runMigration($table); - - foreach (['lazy', 'type', 'flags', 'indexed'] as $column) { - $this->assertTrue($table->hasColumn($column), "Column $column is missing"); - } - $this->assertFalse($table->hasIndex('preferences_app_key')); - $this->assertSame(['userid', 'lazy'], $table->getIndex('prefs_uid_lazy_i')->getColumns()); - $this->assertSame(['appid', 'configkey', 'indexed', 'flags'], $table->getIndex('prefs_app_key_ind_fl_i')->getColumns()); - } - - public function testChangeSchemaWithExistingColumnsAndIndexes(): void { - $table = $this->createPreferencesTable(); - $table->addColumn('lazy', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'length' => 1, 'unsigned' => true]); - $table->addColumn('type', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'unsigned' => true]); - $table->addColumn('flags', Types::INTEGER, ['notnull' => true, 'default' => 0, 'unsigned' => true]); - $table->addColumn('indexed', Types::STRING, ['notnull' => false, 'default' => '', 'length' => 64]); - $table->addIndex(['userid', 'lazy'], 'prefs_uid_lazy_i'); - $table->addIndex(['appid', 'configkey', 'indexed', 'flags'], 'prefs_app_key_ind_fl_i'); - - $this->runMigration($table); - - $this->assertCount(7, $table->getColumns()); - $this->assertCount(2, $table->getIndexes()); - } -} diff --git a/tests/Core/Migrations/Version33000Date20251023120529Test.php b/tests/Core/Migrations/Version33000Date20251023120529Test.php deleted file mode 100644 index 20f06531984a1..0000000000000 --- a/tests/Core/Migrations/Version33000Date20251023120529Test.php +++ /dev/null @@ -1,58 +0,0 @@ -addColumn('bucket_name', Types::STRING, ['length' => 40]); - $table->addColumn('object_store_name', Types::STRING, ['length' => 40]); - return $table; - } - - private function runMigration(Table $table): void { - $schema = $this->createMock(ISchemaWrapper::class); - $schema->method('hasTable') - ->with('preview_locations') - ->willReturn(true); - $schema->method('getTable') - ->with('preview_locations') - ->willReturn($table); - - $migration = new Version33000Date20251023120529($this->createMock(IDBConnection::class)); - $this->assertSame($schema, $migration->changeSchema($this->createMock(IOutput::class), fn () => $schema, [])); - } - - public function testChangeSchemaAddsUniqueIndex(): void { - $table = $this->createPreviewLocationsTable(); - - $this->runMigration($table); - - $this->assertTrue($table->getIndex('unique_bucket_store')->isUnique()); - } - - public function testChangeSchemaWithExistingUniqueIndex(): void { - $table = $this->createPreviewLocationsTable(); - $table->addUniqueIndex(['bucket_name', 'object_store_name'], 'unique_bucket_store'); - - $this->runMigration($table); - - $this->assertCount(1, $table->getIndexes()); - } -}