Skip to content

Commit 43530f6

Browse files
authored
[MB-1761] Update autoincrements (TheSoftwareHouse#16)
* Update auto_increments * Read Auto_increment not Max value
1 parent ca53030 commit 43530f6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Command/FinishCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
9292
$this->schemaManipulator->recreateIndexes();
9393
$output->writeln(' - recreating foreign keys...');
9494
$this->schemaManipulator->recreateForeignKeys();
95+
$output->writeln(' - updating auto_increments...');
96+
$this->schemaManipulator->updateAutoIncrements();
9597
} catch (\Exception $exception) {
9698
$this->outputMessage(sprintf("There has been an error:\n\n%s", $exception->getMessage()), $io);
9799

src/Fogger/Schema/SchemaManipulator.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SchemaManipulator
1616
public function __construct(Connection $source, Connection $target)
1717
{
1818
$this->sourceConnection = $source;
19+
$this->targetConnection = $target;
1920
$this->sourceSchema = $source->getSchemaManager();
2021
$this->targetSchema = $target->getSchemaManager();
2122
}
@@ -99,6 +100,29 @@ private function recreateForeignKeysOnTable(DBAL\Table $table)
99100
}
100101
}
101102

103+
public function updateAutoIncrements()
104+
{
105+
$sourceTables = $this->sourceSchema->listTables();
106+
foreach ($sourceTables as $table) {
107+
foreach ($table->getColumns() as $column) {
108+
if ($column->getAutoincrement()) {
109+
$auto_inc = $this->sourceConnection->fetchAssoc(
110+
"SHOW TABLE STATUS WHERE Name LIKE '".$table->getName()."'"
111+
)['Auto_increment'];
112+
echo(sprintf(
113+
" - %s auto_increment to %s\n",
114+
$table->getName(),
115+
$auto_inc
116+
));
117+
$this->targetConnection->query(
118+
"ALTER TABLE ".$table->getName()." AUTO_INCREMENT = ". $auto_inc
119+
);
120+
break;
121+
}
122+
}
123+
}
124+
}
125+
102126
public function recreateIndexes()
103127
{
104128
$sourceTables = $this->sourceSchema->listTables();

0 commit comments

Comments
 (0)