Skip to content

Commit

Permalink
Do not allow the start_time to be updated when setting a breakpoint
Browse files Browse the repository at this point in the history
This is a bug fix issue #1047

@todo Amend the start_time column to NOT be automatically update when the
phinxlog row is amended.
  • Loading branch information
Richard Quadling authored and Richard Quadling committed Feb 28, 2017
1 parent c6ee30d commit ed66edd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<phpunit bootstrap="./tests/phpunit-bootstrap.php">
<phpunit
bootstrap="./tests/phpunit-bootstrap.php"
colors="true"
columns="max"
>

<!--
* This section defines configuration for running the Phinx unit tests. Some tests
Expand Down
10 changes: 6 additions & 4 deletions src/Phinx/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,14 @@ public function toggleBreakpoint(MigrationInterface $migration)
{
$this->query(
sprintf(
'UPDATE %1$s SET %2$s = CASE %2$s WHEN %3$s THEN %4$s ELSE %3$s END WHERE %5$s = \'%6$s\';',
'UPDATE %1$s SET %2$s = CASE %2$s WHEN %3$s THEN %4$s ELSE %3$s END, %7$s = %7$s WHERE %5$s = \'%6$s\';',
$this->getSchemaTableName(),
$this->quoteColumnName('breakpoint'),
$this->castToBool(true),
$this->castToBool(false),
$this->quoteColumnName('version'),
$migration->getVersion()
$migration->getVersion(),
$this->quoteColumnName('start_time')
)
);

Expand All @@ -481,10 +482,11 @@ public function resetAllBreakpoints()
{
return $this->execute(
sprintf(
'UPDATE %1$s SET %2$s = %3$s WHERE %2$s <> %3$s;',
'UPDATE %1$s SET %2$s = %3$s, %4$s = %4$s WHERE %2$s <> %3$s;',
$this->getSchemaTableName(),
$this->quoteColumnName('breakpoint'),
$this->castToBool(false)
$this->castToBool(false),
$this->quoteColumnName('start_time')
)
);
}
Expand Down
28 changes: 27 additions & 1 deletion tests/Phinx/Migration/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,19 +820,45 @@ public function testBreakpointsOperateAsExpected()
$this->manager->setConfig($config);
$this->manager->migrate('production');

$versions = $this->manager->getEnvironment('production')->getVersionLog();
$lastVersion = end($versions);

// Wait until the second has changed.
$now = time();
while($now == time());

// set breakpoint on most recent migration
$this->manager->toggleBreakpoint('production', null);

// ensure breakpoint is set
$versions = $this->manager->getEnvironment('production')->getVersionLog();
$this->assertEquals(1, end($versions)['breakpoint']);
$currentVersion = end($versions);
$this->assertEquals(1, $currentVersion['breakpoint']);

// ensure no other data has changed.
foreach($lastVersion as $key => $value) {
if (!is_numeric($key) && $key != 'breakpoint') {
$this->assertEquals($value, $currentVersion[$key]);
}
}

// Wait until the second has changed.
$now = time();
while($now == time());

// reset all breakpoints
$this->manager->removeBreakpoints('production');

// ensure breakpoint is not set
$versions = $this->manager->getEnvironment('production')->getVersionLog();
$this->assertEquals(0, end($versions)['breakpoint']);

// ensure no other data has changed.
foreach($lastVersion as $key => $value) {
if (!is_numeric($key) && $key != 'breakpoint') {
$this->assertEquals($value, $currentVersion[$key]);
}
}
}

public function testBreakpointWithInvalidVersion()
Expand Down

0 comments on commit ed66edd

Please sign in to comment.