Skip to content

Commit 304c597

Browse files
authored
Avoid false which is mangled by PDO (#1023)
* Avoid false which is mangled by PDO * Always pass an integer for the breakpoint as suggested by dereuromark * Added test case with an actual migration to ensure we correctly insert the migrations into the unified table. * Fix insert * Fix assertion for the output * phpcs fix * Fix fetching migrations in test * Clean up after upgrade tests to avoid breaking other tests * Fix ci pipeline for mariadb
1 parent 47a7501 commit 304c597

3 files changed

Lines changed: 70 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,29 @@ jobs:
5959
persist-credentials: false
6060

6161
- name: Setup MariaDB
62-
uses: getong/mariadb-action@v1.11
63-
if: matrix.db-type == 'mariadb'
64-
with:
65-
mariadb version: '10.11.10'
66-
mysql database: 'cakephp_test'
67-
mysql root password: 'root'
68-
- name: Setup MariaDB (part 2)
6962
if: matrix.db-type == 'mariadb'
7063
run: |
71-
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_comparisons;'
72-
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_snapshot;'
73-
64+
docker run -d --name=mariadb \
65+
-e MARIADB_ROOT_PASSWORD=root \
66+
-e MARIADB_DATABASE=cakephp_test \
67+
-p 3306:3306 \
68+
--health-cmd="mariadb-admin ping -h 127.0.0.1 -proot || exit 1" \
69+
--health-interval=10s \
70+
--health-timeout=5s \
71+
--health-retries=10 \
72+
mariadb:11.8
73+
74+
echo "Waiting for MariaDB to be ready..."
75+
for i in {1..60}; do
76+
if docker exec mariadb mariadb-admin ping -h 127.0.0.1 -proot >/dev/null 2>&1; then
77+
echo "MariaDB is responding."
78+
break
79+
fi
80+
81+
sleep 2
82+
done
83+
mariadb -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_comparisons;'
84+
mariadb -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_snapshot;'
7485
- name: Setup MySQL
7586
if: matrix.db-type == 'mysql'
7687
run: |

src/Command/UpgradeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ protected function migrateTable(
282282
'plugin' => $plugin,
283283
'start_time' => $row['start_time'] ?? null,
284284
'end_time' => $row['end_time'] ?? null,
285-
'breakpoint' => $row['breakpoint'] ?? 0,
285+
'breakpoint' => (int)($row['breakpoint'] ?? 0),
286286
]);
287287
$insertQuery->execute();
288288
} catch (QueryException $e) {

tests/TestCase/Command/UpgradeCommandTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public function setUp(): void
2323
$connection->execute('DROP TABLE IF EXISTS cake_migrations');
2424
}
2525

26+
public function tearDown(): void
27+
{
28+
$this->clearMigrationRecords('test');
29+
30+
/** @var \Cake\Database\Connection $connection */
31+
$connection = ConnectionManager::get('test');
32+
$connection->execute('DROP TABLE IF EXISTS cake_migrations');
33+
34+
parent::tearDown();
35+
}
36+
2637
protected function getAdapter(): AdapterInterface
2738
{
2839
$config = ConnectionManager::getConfig('test');
@@ -118,4 +129,41 @@ public function testExecuteSimpleExecuteDropTables(): void
118129
$this->assertTrue($adapter->hasTable('cake_migrations'));
119130
$this->assertFalse($adapter->hasTable('phinxlog'));
120131
}
132+
133+
public function testExecuteWithMigrations(): void
134+
{
135+
Configure::write('Migrations.legacyTables', true);
136+
try {
137+
$this->getAdapter()->createSchemaTable();
138+
} catch (Exception $e) {
139+
// Table probably exists
140+
}
141+
142+
$this->getAdapter()->getInsertBuilder()
143+
->insert(['version', 'migration_name', 'breakpoint'])
144+
->into('phinxlog')
145+
->values([
146+
'version' => '20250118143003',
147+
'migration_name' => 'TestMigration',
148+
'breakpoint' => 0,
149+
])
150+
->execute();
151+
152+
$this->exec('migrations upgrade -c test');
153+
$this->assertExitSuccess();
154+
// Check for status output
155+
$this->assertOutputContains('Creating unified table');
156+
$this->assertOutputContains('Total records migrated');
157+
158+
// Validate record in the unified table
159+
$this->assertTrue($this->getAdapter()->hasTable('cake_migrations'));
160+
161+
$rows = $this->getAdapter()->getSelectBuilder()
162+
->select(['version', 'migration_name', 'breakpoint'])
163+
->from('cake_migrations')
164+
->where(['migration_name' => 'TestMigration'])
165+
->all();
166+
167+
$this->assertCount(1, $rows);
168+
}
121169
}

0 commit comments

Comments
 (0)