Skip to content

Commit

Permalink
Merge pull request #9555 from laboro/fix/BAP-14467
Browse files Browse the repository at this point in the history
BAP-14467: Impossible to upgrade from 1.12 to 2.0 version due to Data…
  • Loading branch information
br0ther authored Apr 12, 2017
2 parents a54997d + 168b93f commit 8784f61
Showing 1 changed file with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function up(Schema $schema, QueryBag $queries)

protected function resolveDuplicates()
{
if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
$platform = $this->connection->getDatabasePlatform();

if ($platform instanceof PostgreSqlPlatform) {
$this->connection->exec('CREATE TEMPORARY SEQUENCE seq_temp_version START 1');
}

Expand All @@ -49,31 +51,39 @@ protected function resolveDuplicates()
}

foreach ($rows as $row) {
if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
$this->connection->exec(
'UPDATE oro_audit SET version = 0 ' .
'WHERE object_id = \'' . $row['object_id'] . '\' AND '.
'object_class = \'' . $row['object_class'] . '\';' .
if ($platform instanceof PostgreSqlPlatform) {
$sql = 'UPDATE oro_audit SET version = 0 ' .
'WHERE object_id = :object_id AND '.
'object_class = :object_class;' .
'SELECT setval(\'seq_temp_version\', 1);' .
'UPDATE oro_audit SET version = nextval(\'seq_temp_version\') - 1 ' .
'WHERE object_id = \'' . $row['object_id'] . '\' AND '.
'object_class = \'' . $row['object_class'] . '\';'
);
'WHERE object_id = :object_id AND '.
'object_class = :object_class;';
} else {
$this->connection->exec(
'UPDATE oro_audit SET version = 0 ' .
'WHERE object_id = \'' . $row['object_id'] . '\' AND '.
'object_class = \'' . $row['object_class'] . '\';' .
'SET @version = 0;' .
'UPDATE oro_audit SET version = @version:=@version+1 ' .
'WHERE object_id = \'' . $row['object_id'] . '\' AND '.
'object_class = \'' . $row['object_class'] . '\';'
);
$sql = 'UPDATE oro_audit SET version = 0 ' .
'WHERE object_id = :object_id AND '.
'object_class = :object_class;'.
'SET @version = 0;'.
'UPDATE oro_audit SET version = @version:=@version+1 '.
'WHERE object_id = :object_id AND '.
'object_class = :object_class;';
}

$this->connection->executeUpdate(
$sql,
[
'object_id' => $row['object_id'],
'object_class' => $row['object_class'],
],
[
'object_id' => 'integer',
'object_class' => 'string',
]
);
}
}

if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
if ($platform instanceof PostgreSqlPlatform) {
$this->connection->exec('DROP SEQUENCE seq_temp_version');
}
}
Expand Down

0 comments on commit 8784f61

Please sign in to comment.