From bd3a59e9ca95a57b682a4e5085584b82e394adb3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 23 Oct 2021 15:44:56 +0200 Subject: [PATCH 1/5] Updated to doctrine-migrations 3.3 --- composer.json | 4 ++-- config/test/bootstrap_api_tests.php | 2 +- config/test/bootstrap_db_tests.php | 2 +- module/CLI/src/Command/Db/CreateDatabaseCommand.php | 4 ++-- module/CLI/test/Command/Db/CreateDatabaseCommandTest.php | 4 ++-- module/Rest/test/Action/HealthActionTest.php | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index aa13a8473..0ce15c6e6 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "akrabat/ip-address-middleware": "^2.0", "cakephp/chronos": "^2.2", "cocur/slugify": "^4.0", - "doctrine/migrations": "^3.2 <3.3", + "doctrine/migrations": "^3.3", "doctrine/orm": "^2.9", "endroid/qr-code": "^4.2", "geoip2/geoip2": "^2.11", @@ -73,7 +73,7 @@ "phpunit/phpunit": "^9.5", "roave/security-advisories": "dev-master", "shlinkio/php-coding-standard": "~2.2.0", - "shlinkio/shlink-test-utils": "^2.2", + "shlinkio/shlink-test-utils": "^2.3", "symfony/var-dumper": "^5.3", "veewee/composer-run-parallel": "^1.0" }, diff --git a/config/test/bootstrap_api_tests.php b/config/test/bootstrap_api_tests.php index 7bda8c100..8d22d0299 100644 --- a/config/test/bootstrap_api_tests.php +++ b/config/test/bootstrap_api_tests.php @@ -29,6 +29,6 @@ ); }); -$testHelper->createTestDb(); +$testHelper->createTestDb(['bin/cli', 'db:create'], ['bin/cli', 'db:migrate']); ApiTest\ApiTestCase::setApiClient($httpClient); ApiTest\ApiTestCase::setSeedFixturesCallback(fn () => $testHelper->seedFixtures($em, $config['data_fixtures'] ?? [])); diff --git a/config/test/bootstrap_db_tests.php b/config/test/bootstrap_db_tests.php index 9f14c38db..0237d7416 100644 --- a/config/test/bootstrap_db_tests.php +++ b/config/test/bootstrap_db_tests.php @@ -8,5 +8,5 @@ /** @var ContainerInterface $container */ $container = require __DIR__ . '/../container.php'; -$container->get(Helper\TestHelper::class)->createTestDb(); +$container->get(Helper\TestHelper::class)->createTestDb(['bin/cli', 'db:create'], ['bin/cli', 'db:migrate']); DbTest\DatabaseTestCase::setEntityManager($container->get('em')); diff --git a/module/CLI/src/Command/Db/CreateDatabaseCommand.php b/module/CLI/src/Command/Db/CreateDatabaseCommand.php index 428140e55..a294da9e9 100644 --- a/module/CLI/src/Command/Db/CreateDatabaseCommand.php +++ b/module/CLI/src/Command/Db/CreateDatabaseCommand.php @@ -67,7 +67,7 @@ private function checkDbExists(): void // In order to create the new database, we have to use a connection where the dbname was not set. // Otherwise, it will fail to connect and will not be able to create the new database - $schemaManager = $this->noDbNameConn->getSchemaManager(); + $schemaManager = $this->noDbNameConn->createSchemaManager(); $databases = $schemaManager->listDatabases(); $shlinkDatabase = $this->regularConn->getDatabase(); @@ -80,7 +80,7 @@ private function schemaExists(): bool { // If at least one of the shlink tables exist, we will consider the database exists somehow. // Any inconsistency should be taken care by the migrations - $schemaManager = $this->regularConn->getSchemaManager(); + $schemaManager = $this->regularConn->createSchemaManager(); return ! empty($schemaManager->listTableNames()); } } diff --git a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php index 70d4d5eb8..f77f6b79e 100644 --- a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php +++ b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php @@ -46,10 +46,10 @@ public function setUp(): void $this->databasePlatform = $this->prophesize(AbstractPlatform::class); $this->regularConn = $this->prophesize(Connection::class); - $this->regularConn->getSchemaManager()->willReturn($this->schemaManager->reveal()); + $this->regularConn->createSchemaManager()->willReturn($this->schemaManager->reveal()); $this->regularConn->getDatabasePlatform()->willReturn($this->databasePlatform->reveal()); $noDbNameConn = $this->prophesize(Connection::class); - $noDbNameConn->getSchemaManager()->willReturn($this->schemaManager->reveal()); + $noDbNameConn->createSchemaManager()->willReturn($this->schemaManager->reveal()); $command = new CreateDatabaseCommand( $locker->reveal(), diff --git a/module/Rest/test/Action/HealthActionTest.php b/module/Rest/test/Action/HealthActionTest.php index 1fbad63d3..a233087a7 100644 --- a/module/Rest/test/Action/HealthActionTest.php +++ b/module/Rest/test/Action/HealthActionTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Result; use Doctrine\ORM\EntityManagerInterface; use Exception; use Laminas\Diactoros\Response\JsonResponse; @@ -27,8 +28,7 @@ class HealthActionTest extends TestCase public function setUp(): void { $this->conn = $this->prophesize(Connection::class); - $this->conn->executeQuery(Argument::cetera())->will(function (): void { - }); + $this->conn->executeQuery(Argument::cetera())->willReturn($this->prophesize(Result::class)->reveal()); $dbPlatform = $this->prophesize(AbstractPlatform::class); $dbPlatform->getDummySelectSQL()->willReturn(''); $this->conn->getDatabasePlatform()->willReturn($dbPlatform->reveal()); From cd35770d262eb30b4cc2f42128037daafa4851ed Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 23 Oct 2021 16:02:29 +0200 Subject: [PATCH 2/5] Ensured migrations are not transactional when run in mysql --- CHANGELOG.md | 1 + config/test/bootstrap_db_tests.php | 2 +- data/migrations/Version20160819142757.php | 7 ++++++- data/migrations/Version20160820191203.php | 5 +++++ data/migrations/Version20171021093246.php | 5 +++++ data/migrations/Version20171022064541.php | 5 +++++ data/migrations/Version20180801183328.php | 5 +++++ data/migrations/Version20180913205455.php | 5 +++++ data/migrations/Version20180915110857.php | 5 +++++ data/migrations/Version20181020060559.php | 5 +++++ data/migrations/Version20181020065148.php | 5 +++++ data/migrations/Version20181110175521.php | 5 +++++ data/migrations/Version20190824075137.php | 5 +++++ data/migrations/Version20190930165521.php | 5 +++++ data/migrations/Version20191001201532.php | 5 +++++ data/migrations/Version20191020074522.php | 5 +++++ data/migrations/Version20200105165647.php | 5 +++++ data/migrations/Version20200106215144.php | 5 +++++ data/migrations/Version20200110182849.php | 5 +++++ data/migrations/Version20200323190014.php | 5 +++++ data/migrations/Version20200503170404.php | 5 +++++ data/migrations/Version20201023090929.php | 5 +++++ data/migrations/Version20201102113208.php | 5 +++++ data/migrations/Version20210102174433.php | 5 +++++ data/migrations/Version20210118153932.php | 5 +++++ data/migrations/Version20210202181026.php | 5 +++++ data/migrations/Version20210207100807.php | 5 +++++ data/migrations/Version20210306165711.php | 5 +++++ data/migrations/Version20210522051601.php | 5 +++++ data/migrations/Version20210522124633.php | 5 +++++ data/migrations/Version20210720143824.php | 5 +++++ data/migrations/Version20211002072605.php | 5 +++++ data/migrations_template.txt | 5 +++++ 33 files changed, 158 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baa31e0c7..2e8dae6f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ### Fixed * [#1210](https://github.com/shlinkio/shlink/issues/1210) Fixed real time updates not being notified. +* [#1211](https://github.com/shlinkio/shlink/issues/1211) Fixed `There is no active transaction` error when running migrations in MySQL/Mariadb after updating to doctrine-migrations 3.3. ## [2.9.1] - 2021-10-11 diff --git a/config/test/bootstrap_db_tests.php b/config/test/bootstrap_db_tests.php index 0237d7416..9f14c38db 100644 --- a/config/test/bootstrap_db_tests.php +++ b/config/test/bootstrap_db_tests.php @@ -8,5 +8,5 @@ /** @var ContainerInterface $container */ $container = require __DIR__ . '/../container.php'; -$container->get(Helper\TestHelper::class)->createTestDb(['bin/cli', 'db:create'], ['bin/cli', 'db:migrate']); +$container->get(Helper\TestHelper::class)->createTestDb(); DbTest\DatabaseTestCase::setEntityManager($container->get('em')); diff --git a/data/migrations/Version20160819142757.php b/data/migrations/Version20160819142757.php index 2901836eb..773a4d9b7 100644 --- a/data/migrations/Version20160819142757.php +++ b/data/migrations/Version20160819142757.php @@ -39,6 +39,11 @@ public function up(Schema $schema): void */ public function down(Schema $schema): void { - $db = $this->connection->getDatabasePlatform()->getName(); + $this->connection->getDatabasePlatform()->getName(); + } + + public function isTransactional(): bool + { + return false; } } diff --git a/data/migrations/Version20160820191203.php b/data/migrations/Version20160820191203.php index d0a4d6735..592e556e5 100644 --- a/data/migrations/Version20160820191203.php +++ b/data/migrations/Version20160820191203.php @@ -73,4 +73,9 @@ public function down(Schema $schema): void $schema->dropTable('short_urls_in_tags'); $schema->dropTable('tags'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20171021093246.php b/data/migrations/Version20171021093246.php index 83f08e414..92c078fa8 100644 --- a/data/migrations/Version20171021093246.php +++ b/data/migrations/Version20171021093246.php @@ -45,4 +45,9 @@ public function down(Schema $schema): void $shortUrls->dropColumn('valid_since'); $shortUrls->dropColumn('valid_until'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20171022064541.php b/data/migrations/Version20171022064541.php index 7ff39666b..88b5f4689 100644 --- a/data/migrations/Version20171022064541.php +++ b/data/migrations/Version20171022064541.php @@ -42,4 +42,9 @@ public function down(Schema $schema): void $shortUrls->dropColumn('max_visits'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20180801183328.php b/data/migrations/Version20180801183328.php index 24bcd825d..14f2b22cc 100644 --- a/data/migrations/Version20180801183328.php +++ b/data/migrations/Version20180801183328.php @@ -39,4 +39,9 @@ private function setSize(Schema $schema, int $size): void { $schema->getTable('short_urls')->getColumn('short_code')->setLength($size); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20180913205455.php b/data/migrations/Version20180913205455.php index 727e44004..23d51d792 100644 --- a/data/migrations/Version20180913205455.php +++ b/data/migrations/Version20180913205455.php @@ -66,4 +66,9 @@ public function down(Schema $schema): void { // Nothing to rollback } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20180915110857.php b/data/migrations/Version20180915110857.php index 73a365973..8b83053b8 100644 --- a/data/migrations/Version20180915110857.php +++ b/data/migrations/Version20180915110857.php @@ -47,4 +47,9 @@ public function down(Schema $schema): void { // Nothing to run } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20181020060559.php b/data/migrations/Version20181020060559.php index 78cd86146..85d2c9bab 100644 --- a/data/migrations/Version20181020060559.php +++ b/data/migrations/Version20181020060559.php @@ -65,4 +65,9 @@ public function down(Schema $schema): void { // No down } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20181020065148.php b/data/migrations/Version20181020065148.php index 62b14ccf3..e7b3cf5f0 100644 --- a/data/migrations/Version20181020065148.php +++ b/data/migrations/Version20181020065148.php @@ -38,4 +38,9 @@ public function down(Schema $schema): void { // No down } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20181110175521.php b/data/migrations/Version20181110175521.php index aae8d4192..6e26837ef 100644 --- a/data/migrations/Version20181110175521.php +++ b/data/migrations/Version20181110175521.php @@ -34,4 +34,9 @@ private function getUserAgentColumn(Schema $schema): Column { return $schema->getTable('visits')->getColumn('user_agent'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20190824075137.php b/data/migrations/Version20190824075137.php index 208d85a36..0681e6fef 100644 --- a/data/migrations/Version20190824075137.php +++ b/data/migrations/Version20190824075137.php @@ -34,4 +34,9 @@ private function getRefererColumn(Schema $schema): Column { return $schema->getTable('visits')->getColumn('referer'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20190930165521.php b/data/migrations/Version20190930165521.php index 2e4e8f50b..5699863c5 100644 --- a/data/migrations/Version20190930165521.php +++ b/data/migrations/Version20190930165521.php @@ -52,4 +52,9 @@ public function down(Schema $schema): void $schema->getTable('short_urls')->dropColumn('domain_id'); $schema->dropTable('domains'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20191001201532.php b/data/migrations/Version20191001201532.php index d067101c7..20de04865 100644 --- a/data/migrations/Version20191001201532.php +++ b/data/migrations/Version20191001201532.php @@ -46,4 +46,9 @@ public function down(Schema $schema): void $shortUrls->dropIndex('unique_short_code_plus_domain'); $shortUrls->addUniqueIndex(['short_code']); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20191020074522.php b/data/migrations/Version20191020074522.php index baf1ce7ac..b225f7330 100644 --- a/data/migrations/Version20191020074522.php +++ b/data/migrations/Version20191020074522.php @@ -34,4 +34,9 @@ private function getOriginalUrlColumn(Schema $schema): Column { return $schema->getTable('short_urls')->getColumn('original_url'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20200105165647.php b/data/migrations/Version20200105165647.php index e0e31f55b..ed68850a8 100644 --- a/data/migrations/Version20200105165647.php +++ b/data/migrations/Version20200105165647.php @@ -93,4 +93,9 @@ public function down(Schema $schema): void $visitLocations->dropColumn($colName); } } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20200106215144.php b/data/migrations/Version20200106215144.php index 5682baafd..0b760ced8 100644 --- a/data/migrations/Version20200106215144.php +++ b/data/migrations/Version20200106215144.php @@ -44,4 +44,9 @@ public function down(Schema $schema): void ]); } } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20200110182849.php b/data/migrations/Version20200110182849.php index 16b858f98..6c66788e3 100644 --- a/data/migrations/Version20200110182849.php +++ b/data/migrations/Version20200110182849.php @@ -50,4 +50,9 @@ public function down(Schema $schema): void { // No need (and no way) to undo this migration } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20200323190014.php b/data/migrations/Version20200323190014.php index 47cf402a1..92abb87c4 100644 --- a/data/migrations/Version20200323190014.php +++ b/data/migrations/Version20200323190014.php @@ -42,4 +42,9 @@ public function down(Schema $schema): void $visitLocations->dropColumn('is_empty'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20200503170404.php b/data/migrations/Version20200503170404.php index a102c2c8d..418cbea31 100644 --- a/data/migrations/Version20200503170404.php +++ b/data/migrations/Version20200503170404.php @@ -24,4 +24,9 @@ public function down(Schema $schema): void $this->skipIf(! $visits->hasIndex(self::INDEX_NAME)); $visits->dropIndex(self::INDEX_NAME); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20201023090929.php b/data/migrations/Version20201023090929.php index 05d16c223..0a36f06ae 100644 --- a/data/migrations/Version20201023090929.php +++ b/data/migrations/Version20201023090929.php @@ -41,4 +41,9 @@ public function down(Schema $schema): void $shortUrls->dropColumn('import_original_short_code'); $shortUrls->dropIndex('unique_imports'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20201102113208.php b/data/migrations/Version20201102113208.php index 405ca5c71..79cec197a 100644 --- a/data/migrations/Version20201102113208.php +++ b/data/migrations/Version20201102113208.php @@ -83,4 +83,9 @@ public function down(Schema $schema): void $shortUrls->removeForeignKey('FK_' . self::API_KEY_COLUMN); $shortUrls->dropColumn(self::API_KEY_COLUMN); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210102174433.php b/data/migrations/Version20210102174433.php index 835fcbda2..60ce36cf6 100644 --- a/data/migrations/Version20210102174433.php +++ b/data/migrations/Version20210102174433.php @@ -49,4 +49,9 @@ public function down(Schema $schema): void $schema->getTable(self::TABLE_NAME)->dropIndex('UQ_role_plus_api_key'); $schema->dropTable(self::TABLE_NAME); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210118153932.php b/data/migrations/Version20210118153932.php index e17ff533d..d81c4857f 100644 --- a/data/migrations/Version20210118153932.php +++ b/data/migrations/Version20210118153932.php @@ -23,4 +23,9 @@ public function up(Schema $schema): void public function down(Schema $schema): void { } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210202181026.php b/data/migrations/Version20210202181026.php index ccf695729..4ecfa8de0 100644 --- a/data/migrations/Version20210202181026.php +++ b/data/migrations/Version20210202181026.php @@ -33,4 +33,9 @@ public function down(Schema $schema): void $shortUrls->dropColumn(self::TITLE); $shortUrls->dropColumn('title_was_auto_resolved'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210207100807.php b/data/migrations/Version20210207100807.php index 4c4509c44..6d9e98222 100644 --- a/data/migrations/Version20210207100807.php +++ b/data/migrations/Version20210207100807.php @@ -40,4 +40,9 @@ public function down(Schema $schema): void $visits->dropColumn('visited_url'); $visits->dropColumn('type'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210306165711.php b/data/migrations/Version20210306165711.php index 5b4bd166b..cb69741f3 100644 --- a/data/migrations/Version20210306165711.php +++ b/data/migrations/Version20210306165711.php @@ -34,4 +34,9 @@ public function down(Schema $schema): void $apiKeys->dropColumn(self::COLUMN); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210522051601.php b/data/migrations/Version20210522051601.php index 9e2bd19e4..70e0fb347 100644 --- a/data/migrations/Version20210522051601.php +++ b/data/migrations/Version20210522051601.php @@ -23,4 +23,9 @@ public function down(Schema $schema): void $this->skipIf(! $shortUrls->hasColumn('crawlable')); $shortUrls->dropColumn('crawlable'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210522124633.php b/data/migrations/Version20210522124633.php index ea486e930..f56b8a929 100644 --- a/data/migrations/Version20210522124633.php +++ b/data/migrations/Version20210522124633.php @@ -25,4 +25,9 @@ public function down(Schema $schema): void $this->skipIf(! $visits->hasColumn(self::POTENTIAL_BOT_COLUMN)); $visits->dropColumn(self::POTENTIAL_BOT_COLUMN); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20210720143824.php b/data/migrations/Version20210720143824.php index 66e03be55..09e97cfa1 100644 --- a/data/migrations/Version20210720143824.php +++ b/data/migrations/Version20210720143824.php @@ -38,4 +38,9 @@ public function down(Schema $schema): void $domainsTable->dropColumn('regular_not_found_redirect'); $domainsTable->dropColumn('invalid_short_url_redirect'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations/Version20211002072605.php b/data/migrations/Version20211002072605.php index 5f8db9876..03c988852 100644 --- a/data/migrations/Version20211002072605.php +++ b/data/migrations/Version20211002072605.php @@ -23,4 +23,9 @@ public function down(Schema $schema): void $this->skipIf(! $shortUrls->hasColumn('forward_query')); $shortUrls->dropColumn('forward_query'); } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } diff --git a/data/migrations_template.txt b/data/migrations_template.txt index 482236e68..fa6710707 100644 --- a/data/migrations_template.txt +++ b/data/migrations_template.txt @@ -18,4 +18,9 @@ final class extends AbstractMigration { } + + public function isTransactional(): bool + { + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; + } } From 0c3f98cc37eb6e41fb6556ab58f815fe7b025a58 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 23 Oct 2021 16:04:54 +0200 Subject: [PATCH 3/5] Replaced implicit false in migration by a check on the platform --- data/migrations/Version20160819142757.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/migrations/Version20160819142757.php b/data/migrations/Version20160819142757.php index 773a4d9b7..70831eb93 100644 --- a/data/migrations/Version20160819142757.php +++ b/data/migrations/Version20160819142757.php @@ -44,6 +44,6 @@ public function down(Schema $schema): void public function isTransactional(): bool { - return false; + return $this->connection->getDatabasePlatform()->getName() !== 'mysql'; } } From cc6fa312f034ee9753644013c9d19062252f2994 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 23 Oct 2021 16:32:06 +0200 Subject: [PATCH 4/5] Ensured minimum amount of task workers provided via config option or env var is 4 --- composer.json | 2 +- config/autoload/swoole.global.php | 32 ++++++++++++++++++------------- config/constants.php | 1 + 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 0ce15c6e6..118ae2446 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "shlinkio/shlink-config": "^1.2", "shlinkio/shlink-event-dispatcher": "^2.1", "shlinkio/shlink-importer": "^2.3.1", - "shlinkio/shlink-installer": "^6.2", + "shlinkio/shlink-installer": "^6.2.1", "shlinkio/shlink-ip-geolocation": "^2.0", "symfony/console": "^5.3", "symfony/filesystem": "^5.3", diff --git a/config/autoload/swoole.global.php b/config/autoload/swoole.global.php index 3db4cf5ca..ad4e37927 100644 --- a/config/autoload/swoole.global.php +++ b/config/autoload/swoole.global.php @@ -4,22 +4,28 @@ use function Shlinkio\Shlink\Common\env; -return [ +use const Shlinkio\Shlink\MIN_TASK_WORKERS; - 'mezzio-swoole' => [ - // Setting this to true can have unexpected behaviors when running several concurrent slow DB queries - 'enable_coroutine' => false, +return (static function () { + $taskWorkers = (int) env('TASK_WORKER_NUM', 16); - 'swoole-http-server' => [ - 'host' => '0.0.0.0', - 'port' => (int) env('PORT', 8080), - 'process-name' => 'shlink', + return [ - 'options' => [ - 'worker_num' => (int) env('WEB_WORKER_NUM', 16), - 'task_worker_num' => (int) env('TASK_WORKER_NUM', 16), + 'mezzio-swoole' => [ + // Setting this to true can have unexpected behaviors when running several concurrent slow DB queries + 'enable_coroutine' => false, + + 'swoole-http-server' => [ + 'host' => '0.0.0.0', + 'port' => (int) env('PORT', 8080), + 'process-name' => 'shlink', + + 'options' => [ + 'worker_num' => (int) env('WEB_WORKER_NUM', 16), + 'task_worker_num' => $taskWorkers < MIN_TASK_WORKERS ? MIN_TASK_WORKERS : $taskWorkers, + ], ], ], - ], -]; + ]; +})(); diff --git a/config/constants.php b/config/constants.php index 43de270a6..6c7aa09e3 100644 --- a/config/constants.php +++ b/config/constants.php @@ -18,3 +18,4 @@ const DEFAULT_QR_CODE_MARGIN = 0; const DEFAULT_QR_CODE_FORMAT = 'png'; const DEFAULT_QR_CODE_ERROR_CORRECTION = 'l'; +const MIN_TASK_WORKERS = 4; From 2b827baeed0fceef486acba4dfc3593d51fe5317 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 23 Oct 2021 16:35:38 +0200 Subject: [PATCH 5/5] Updated changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e8dae6f2..f895b28b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). -## [Unreleased] +## [2.9.2] - 2021-10-23 ### Added * *Nothing* @@ -18,8 +18,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this * *Nothing* ### Fixed -* [#1210](https://github.com/shlinkio/shlink/issues/1210) Fixed real time updates not being notified. +* [#1210](https://github.com/shlinkio/shlink/issues/1210) Fixed real time updates not being notified due to an incorrect handling of db transactions on multi-process tasks. * [#1211](https://github.com/shlinkio/shlink/issues/1211) Fixed `There is no active transaction` error when running migrations in MySQL/Mariadb after updating to doctrine-migrations 3.3. +* [#1197](https://github.com/shlinkio/shlink/issues/1197) Fixed amount of task workers provided via config option or env var not being validated to ensure enough workers to process all parallel tasks. ## [2.9.1] - 2021-10-11