Skip to content

Commit

Permalink
Added returns min_value and increment_by on sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
iamwildtuna committed Mar 25, 2021
1 parent 1f5a8a8 commit fbfeb6e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Schema/CockroachSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ protected function _getPortableSequenceDefinition($sequence)
$sequenceName = $sequence['relname'];
}

if (! isset($sequence['increment_by'], $sequence['min_value'])) {
if (!isset($sequence['increment_by'], $sequence['min_value'])) {
$sequence['min_value'] = 0;
$sequence['increment_by'] = 0;
// /** @var string[] $data */
// $data = $this->_conn->fetchAssoc(
// 'SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName)
// );
//
// $sequence += $data;

/** @var string[] $data */
$data = $this->_conn->fetchAssoc('SHOW CREATE ' . $this->_platform->quoteIdentifier($sequenceName));
if (!empty($data['create_statement'])) {
$matches = [];
preg_match_all('/ -?\d+/', $data['create_statement'], $matches);
if (!empty($matches[0])) {
$matches = array_map('trim', $matches[0]);
$sequence['min_value'] = $matches[0];
$sequence['increment_by'] = $matches[2];
}
}
}

return new Sequence($sequenceName, (int) $sequence['increment_by'], (int) $sequence['min_value']);
Expand Down

0 comments on commit fbfeb6e

Please sign in to comment.