Skip to content

Commit 2c827a6

Browse files
authored
Merge pull request #16 from netlogix/feat/postgresql
2 parents fbdf951 + 5dc3aad commit 2c827a6

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

Classes/Command/MigrationsCommandController.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Netlogix\Migrations\Command;
55

66
use Doctrine\DBAL\Connection;
7+
use Doctrine\DBAL\Platforms\MySqlPlatform;
78
use Doctrine\ORM\EntityManagerInterface;
89
use Neos\Flow\Annotations as Flow;
910
use Neos\Flow\Cli\CommandController;
@@ -121,12 +122,19 @@ protected function increaseDatabaseTimeout($timeout = 3600): void
121122
{
122123
ini_set('default_socket_timeout', (string)$timeout);
123124
if (!$this->entityManager instanceof EntityManagerInterface) {
124-
throw new RuntimeException('No Doctrine EntityManager found, cannot increase MySQL timeout');
125+
throw new RuntimeException('No Doctrine EntityManager found, cannot increase database timeout');
125126
}
126127
$connection = $this->entityManager->getConnection();
127128
if (!$connection || !$connection instanceof Connection) {
128-
throw new RuntimeException('No Doctrine Connection found, cannot increase MySQL timeout');
129+
throw new RuntimeException('No Doctrine Connection found, cannot increase database timeout');
130+
}
131+
132+
if ($connection->getDatabasePlatform() instanceof MySqlPlatform) {
133+
$connection->executeStatement(sprintf('SET SESSION wait_timeout = %d;', $timeout));
134+
} elseif ($connection->getDatabasePlatform()->getName() === 'postgresql') {
135+
$connection->executeStatement(sprintf('SET SESSION statement_timeout = %d;', $timeout * 1000));
136+
} else {
137+
$this->outputLine('<error>Unsupported database platform "%s", cannot increase database timeout</error>', [$connection->getDatabasePlatform()->getName()]);
129138
}
130-
$connection->exec(sprintf('SET SESSION wait_timeout = %d;', $timeout));
131139
}
132140
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Neos\Flow\Persistence\Doctrine\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20190930132259 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->abortIf(
24+
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\PostgreSQL100Platform,
25+
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQL100Platform'."
26+
);
27+
28+
$this->addSql('CREATE TABLE netlogix_migrationstatus (version VARCHAR(255) NOT NULL, PRIMARY KEY(version))');
29+
}
30+
31+
public function down(Schema $schema): void
32+
{
33+
// this down() migration is auto-generated, please modify it to your needs
34+
$this->abortIf(
35+
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\PostgreSQL100Platform,
36+
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQL100Platform'."
37+
);
38+
39+
$this->addSql('DROP TABLE netlogix_migrationstatus');
40+
}
41+
}

0 commit comments

Comments
 (0)