Skip to content

Commit ea23056

Browse files
MCLOUD-5735: Add support for auto_increment option #195 (#200)
1 parent a576a02 commit ea23056

File tree

9 files changed

+81
-9
lines changed

9 files changed

+81
-9
lines changed

src/Command/BuildCompose.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ protected function configure(): void
226226
null,
227227
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
228228
'Environment variable for elasticsearch service'
229+
)->addOption(
230+
Source\CliSource::OPTION_DB_INCREMENT_INCREMENT,
231+
null,
232+
InputOption::VALUE_REQUIRED,
233+
'"auto_increment_increment" database variable'
234+
)->addOption(
235+
Source\CliSource::OPTION_DB_INCREMENT_OFFSET,
236+
null,
237+
InputOption::VALUE_REQUIRED,
238+
'"auto_increment_offset" database variable'
229239
);
230240

231241
parent::configure();

src/Compose/ProductionBuilder.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ private function addDbService(
464464
): void {
465465
$volumePrefix = $config->getNameWithPrefix();
466466
$mounts[] = $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d';
467+
$commands = [];
467468

468469
switch ($service) {
469470
case self::SERVICE_DB:
@@ -478,6 +479,15 @@ private function addDbService(
478479
$mounts[] = $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql';
479480
$mounts[] = self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d';
480481
$serviceType = ServiceInterface::SERVICE_DB;
482+
483+
if ($config->getDbIncrementIncrement() > 1) {
484+
$commands[] = '--auto_increment_increment=' . $config->getDbIncrementIncrement();
485+
}
486+
487+
if ($config->getDbIncrementOffset() > 1) {
488+
$commands[] = '--auto_increment_offset=' . $config->getDbIncrementOffset();
489+
}
490+
481491
break;
482492
case self::SERVICE_DB_QUOTE:
483493
$port = $config->getDbQuotePortsExpose();
@@ -511,15 +521,21 @@ private function addDbService(
511521
throw new GenericException(sprintf('Configuration for %s service not exist', $service));
512522
}
513523

524+
$dbConfig = [
525+
'ports' => [$port ? "$port:3306" : '3306'],
526+
'volumes' => $mounts,
527+
];
528+
529+
if ($commands) {
530+
$dbConfig['command'] = implode(' ', $commands);
531+
}
532+
514533
$manager->addService(
515534
$service,
516535
$this->serviceFactory->create(
517536
$serviceType,
518537
$version,
519-
[
520-
'ports' => [$port ? "$port:3306" : '3306'],
521-
'volumes' => $mounts,
522-
]
538+
$dbConfig
523539
),
524540
[self::NETWORK_MAGENTO],
525541
[]

src/Config/Config.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,28 @@ public function getMagentoVersion(): ?string
388388
{
389389
return $this->all()->get(SourceInterface::MAGENTO_VERSION);
390390
}
391+
392+
/**
393+
* @return int
394+
* @throws ConfigurationMismatchException
395+
*/
396+
public function getDbIncrementIncrement(): int
397+
{
398+
return max(
399+
(int)$this->all()->get(SourceInterface::SYSTEM_DB_INCREMENT_INCREMENT, 1),
400+
1
401+
);
402+
}
403+
404+
/**
405+
* @return int
406+
* @throws ConfigurationMismatchException
407+
*/
408+
public function getDbIncrementOffset(): int
409+
{
410+
return max(
411+
(int)$this->all()->get(SourceInterface::SYSTEM_DB_INCREMENT_OFFSET, 1),
412+
1
413+
);
414+
}
391415
}

src/Config/Source/CliSource.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class CliSource implements SourceInterface
5555
public const OPTION_HOST = 'host';
5656
public const OPTION_PORT = 'port';
5757

58+
public const OPTION_DB_INCREMENT_INCREMENT = 'db-increment-increment';
59+
public const OPTION_DB_INCREMENT_OFFSET = 'db-increment-offset';
60+
5861
/**
5962
* Environment variable for elasticsearch service.
6063
*/
@@ -213,6 +216,14 @@ public function read(): Repository
213216
$repository->set(self::SERVICES_ES_VARS, $esEnvVars);
214217
}
215218

219+
if ($incrementIncrement = $this->input->getOption(self::OPTION_DB_INCREMENT_INCREMENT)) {
220+
$repository->set(SourceInterface::SYSTEM_DB_INCREMENT_INCREMENT, $incrementIncrement);
221+
}
222+
223+
if ($incrementOffset = $this->input->getOption(self::OPTION_DB_INCREMENT_OFFSET)) {
224+
$repository->set(SourceInterface::SYSTEM_DB_INCREMENT_OFFSET, $incrementOffset);
225+
}
226+
216227
return $repository;
217228
}
218229
}

src/Config/Source/SourceInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ interface SourceInterface
120120
public const SYSTEM_EXPOSE_DB_QUOTE_PORTS = 'system.expose_db_quote_ports';
121121
public const SYSTEM_EXPOSE_DB_SALES_PORTS = 'system.expose_db_sales_ports';
122122

123+
public const SYSTEM_DB_INCREMENT_INCREMENT = 'system.db.increment_increment';
124+
public const SYSTEM_DB_INCREMENT_OFFSET = 'system.db.increment_offset';
125+
123126
public const VARIABLES = 'variables';
124127

125128
public const HOOKS = 'hooks';

src/Test/Integration/BuildComposeTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public function buildDataProvider(): array
8585
[CliSource::OPTION_WITH_CRON, true],
8686
[CliSource::OPTION_WITH_XDEBUG, true],
8787
[CliSource::OPTION_ES, '5.2'],
88-
[CliSource::OPTION_NO_ES, true]
88+
[CliSource::OPTION_NO_ES, true],
89+
[CliSource::OPTION_DB_INCREMENT_INCREMENT, 3],
90+
[CliSource::OPTION_DB_INCREMENT_OFFSET, 2],
8991
]
9092
]
9193
];

src/Test/Integration/BuildCustomComposeTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ public function buildDataProvider(): array
8181
'system' => [
8282
'mode' => 'production',
8383
'host' => 'magento2.test',
84-
'port' => '8080'
84+
'port' => '8080',
85+
'db' => [
86+
'increment_increment' => 3,
87+
'increment_offset' => 2
88+
]
8589
],
8690
'services' => [
8791
'php' => [
@@ -97,9 +101,9 @@ public function buildDataProvider(): array
97101
],
98102
],
99103
'hooks' => [
100-
'build' => 'set -e
101-
php ./vendor/bin/ece-tools run scenario/build/generate.xml
102-
php ./vendor/bin/ece-tools run scenario/build/transfer.xml',
104+
'build' => 'set -e' . PHP_EOL
105+
. 'php ./vendor/bin/ece-tools run scenario/build/generate.xml' . PHP_EOL
106+
. 'php ./vendor/bin/ece-tools run scenario/build/transfer.xml',
103107
'deploy' => 'php ./vendor/bin/ece-tools run scenario/deploy.xml',
104108
'post_deploy' => 'php ./vendor/bin/ece-tools run scenario/post-deploy.xml'
105109
],

src/Test/Integration/_files/cloud_base_mftf/docker-compose.exp.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d'
1616
- 'mymagento-magento-db:/var/lib/mysql'
1717
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
18+
command: '--auto_increment_increment=3 --auto_increment_offset=2'
1819
networks:
1920
magento:
2021
aliases:

src/Test/Integration/_files/custom_cloud_base/docker-compose.exp.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- 'magento-mariadb-conf:/etc/mysql/mariadb.conf.d'
1616
- 'magento-magento-db:/var/lib/mysql'
1717
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
18+
command: '--auto_increment_increment=3 --auto_increment_offset=2'
1819
networks:
1920
magento:
2021
aliases:

0 commit comments

Comments
 (0)