Skip to content
Merged
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
31 changes: 21 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion src/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
48 changes: 48 additions & 0 deletions tests/TestCase/Command/UpgradeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
}
Loading