Skip to content

Commit

Permalink
try to fix mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Dec 13, 2024
1 parent f9729b3 commit 6ecb6ad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ phpunit-integration: vendor
phpunit-integration-postgres: vendor ## run phpunit integration tests on postgres
DB_URL="pdo-pgsql://postgres:postgres@localhost:5432/eventstore?charset=utf8" vendor/bin/phpunit --testsuite=integration

.PHONY: phpunit-integration-mysql
phpunit-integration-mysql: vendor ## run phpunit integration tests on mysql
DB_URL="pdo-mysql://root@localhost:3306/eventstore?charset=utf8" vendor/bin/phpunit --testsuite=integration

.PHONY: phpunit-unit
phpunit-unit: vendor ## run phpunit unit tests
XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite=unit
Expand Down
10 changes: 9 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ services:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=eventstore
ports:
- 5432:5432
- 5432:5432

mysql:
image: mysql:8
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD="yes"
- MYSQL_DATABASE="eventstore"
ports:
- 3306:3306
21 changes: 19 additions & 2 deletions src/Store/StreamDoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,34 @@ function () use ($messages): void {
$this->executeSave($columns, $placeholders, $parameters, $types, $this->connection);
}

$subselect = null;

foreach ($achievedUntilEventId as $stream => $eventId) {
if ($subselect === null) {
if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
$subselect = sprintf(
'SELECT id FROM (SELECT * FROM %s) WHERE event_id = :event_id',
$this->config['table_name'],
);
} else {
$subselect = sprintf(
'SELECT id FROM %s WHERE event_id = :event_id',
$this->config['table_name'],
);
}
}

$this->connection->executeStatement(
sprintf(
<<<'SQL'
UPDATE %1$s
UPDATE %s
SET archived = true
WHERE stream = :stream
AND id < (SELECT id FROM %1$s WHERE event_id = :event_id)
AND id < (%s)
AND archived = false
SQL,
$this->config['table_name'],
$subselect,
),
[
'stream' => $stream,
Expand Down

0 comments on commit 6ecb6ad

Please sign in to comment.