diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a800224..50cbc1d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,18 +59,29 @@ jobs: persist-credentials: false - name: Setup MariaDB - uses: getong/mariadb-action@v1.11 - if: matrix.db-type == 'mariadb' - with: - mariadb version: '10.11.10' - mysql database: 'cakephp_test' - mysql root password: 'root' - - name: Setup MariaDB (part 2) if: matrix.db-type == 'mariadb' run: | - mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_comparisons;' - mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_snapshot;' - + docker run -d --name=mariadb \ + -e MARIADB_ROOT_PASSWORD=root \ + -e MARIADB_DATABASE=cakephp_test \ + -p 3306:3306 \ + --health-cmd="mariadb-admin ping -h 127.0.0.1 -proot || exit 1" \ + --health-interval=10s \ + --health-timeout=5s \ + --health-retries=10 \ + mariadb:11.8 + + echo "Waiting for MariaDB to be ready..." + for i in {1..60}; do + if docker exec mariadb mariadb-admin ping -h 127.0.0.1 -proot >/dev/null 2>&1; then + echo "MariaDB is responding." + break + fi + + sleep 2 + done + mariadb -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_comparisons;' + mariadb -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_snapshot;' - name: Setup MySQL if: matrix.db-type == 'mysql' run: | diff --git a/src/Command/UpgradeCommand.php b/src/Command/UpgradeCommand.php index 1d766da2..5897c458 100644 --- a/src/Command/UpgradeCommand.php +++ b/src/Command/UpgradeCommand.php @@ -282,7 +282,7 @@ protected function migrateTable( 'plugin' => $plugin, 'start_time' => $row['start_time'] ?? null, 'end_time' => $row['end_time'] ?? null, - 'breakpoint' => $row['breakpoint'] ?? 0, + 'breakpoint' => (int)($row['breakpoint'] ?? 0), ]); $insertQuery->execute(); } catch (QueryException $e) { diff --git a/tests/TestCase/Command/UpgradeCommandTest.php b/tests/TestCase/Command/UpgradeCommandTest.php index 0fe13271..ceddd953 100644 --- a/tests/TestCase/Command/UpgradeCommandTest.php +++ b/tests/TestCase/Command/UpgradeCommandTest.php @@ -23,6 +23,17 @@ public function setUp(): void $connection->execute('DROP TABLE IF EXISTS cake_migrations'); } + public function tearDown(): void + { + $this->clearMigrationRecords('test'); + + /** @var \Cake\Database\Connection $connection */ + $connection = ConnectionManager::get('test'); + $connection->execute('DROP TABLE IF EXISTS cake_migrations'); + + parent::tearDown(); + } + protected function getAdapter(): AdapterInterface { $config = ConnectionManager::getConfig('test'); @@ -118,4 +129,41 @@ public function testExecuteSimpleExecuteDropTables(): void $this->assertTrue($adapter->hasTable('cake_migrations')); $this->assertFalse($adapter->hasTable('phinxlog')); } + + public function testExecuteWithMigrations(): void + { + Configure::write('Migrations.legacyTables', true); + try { + $this->getAdapter()->createSchemaTable(); + } catch (Exception $e) { + // Table probably exists + } + + $this->getAdapter()->getInsertBuilder() + ->insert(['version', 'migration_name', 'breakpoint']) + ->into('phinxlog') + ->values([ + 'version' => '20250118143003', + 'migration_name' => 'TestMigration', + 'breakpoint' => 0, + ]) + ->execute(); + + $this->exec('migrations upgrade -c test'); + $this->assertExitSuccess(); + // Check for status output + $this->assertOutputContains('Creating unified table'); + $this->assertOutputContains('Total records migrated'); + + // Validate record in the unified table + $this->assertTrue($this->getAdapter()->hasTable('cake_migrations')); + + $rows = $this->getAdapter()->getSelectBuilder() + ->select(['version', 'migration_name', 'breakpoint']) + ->from('cake_migrations') + ->where(['migration_name' => 'TestMigration']) + ->all(); + + $this->assertCount(1, $rows); + } }