From 3fff19a2676e52d9fbe3e377e4e04f4c7cdcd8f3 Mon Sep 17 00:00:00 2001 From: Vitalii Zhuk Date: Thu, 9 Oct 2025 08:31:05 +0300 Subject: [PATCH 1/2] Add ClickHouse migration factory. --- composer.json | 3 +- src/Factory/ClickHouseMigrationFactory.php | 30 ++++++++++++ .../MigrationFactoryResolverInterface.php | 21 +++++++++ tests/Migrations/DataSet04/Version01.php | 43 +++++++++++++++++ .../ClickHouseMigrationFactoryTest.php | 46 +++++++++++++++++++ 5 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 src/Factory/ClickHouseMigrationFactory.php create mode 100644 src/Factory/MigrationFactoryResolverInterface.php create mode 100644 tests/Migrations/DataSet04/Version01.php create mode 100644 tests/Unit/Factory/ClickHouseMigrationFactoryTest.php diff --git a/composer.json b/composer.json index 97ea72a..4bb9131 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "matthiasnoback/symfony-dependency-injection-test": "~6.1.0", "symfony/console": "~6.4 | ~7.0", "symfony/dependency-injection": "~6.4 | ~7.0", - "symfony/config": "~6.4 | ~7.0" + "symfony/config": "~6.4 | ~7.0", + "smi2/phpclickhouse": "~1.6.0" }, "minimum-stability": "RC", diff --git a/src/Factory/ClickHouseMigrationFactory.php b/src/Factory/ClickHouseMigrationFactory.php new file mode 100644 index 0000000..b31aeba --- /dev/null +++ b/src/Factory/ClickHouseMigrationFactory.php @@ -0,0 +1,30 @@ +class->newInstance($this->client); + } +} diff --git a/src/Factory/MigrationFactoryResolverInterface.php b/src/Factory/MigrationFactoryResolverInterface.php new file mode 100644 index 0000000..b9a171b --- /dev/null +++ b/src/Factory/MigrationFactoryResolverInterface.php @@ -0,0 +1,21 @@ +client->write('CREATE TABLE test_1 ( + id UInt32, + created_at DATETIME, + label String + ) ENGINE=MergeTree ORDER BY (created_at)'); + } + + public function down(): void + { + $this->client->write('DROP TABLE test_1'); + } +} diff --git a/tests/Unit/Factory/ClickHouseMigrationFactoryTest.php b/tests/Unit/Factory/ClickHouseMigrationFactoryTest.php new file mode 100644 index 0000000..ea7da0f --- /dev/null +++ b/tests/Unit/Factory/ClickHouseMigrationFactoryTest.php @@ -0,0 +1,46 @@ +client = $this->createMock(Client::class); + } + + #[Test] + public function shouldSuccessCreate(): void + { + $factory = new ClickHouseMigrationFactory($this->client); + $metadata = MigrationMetadata::fromPhpFile('clickhouse', __DIR__.'/../../Migrations/DataSet04/Version01.php'); + $migration = $factory->create($metadata); + + self::assertInstanceOf(Version01::class, $migration); + + $refClient = new \ReflectionProperty($migration, 'client'); + $client = $refClient->getValue($migration); + + self::assertEquals($this->client, $client); + } +} From 211be6b437f6ed3c053deb84c7d69dc54fcd29ee Mon Sep 17 00:00:00 2001 From: Vitalii Zhuk Date: Thu, 9 Oct 2025 08:31:57 +0300 Subject: [PATCH 2/2] Remove unused interfaces --- .../MigrationFactoryResolverInterface.php | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/Factory/MigrationFactoryResolverInterface.php diff --git a/src/Factory/MigrationFactoryResolverInterface.php b/src/Factory/MigrationFactoryResolverInterface.php deleted file mode 100644 index b9a171b..0000000 --- a/src/Factory/MigrationFactoryResolverInterface.php +++ /dev/null @@ -1,21 +0,0 @@ -