diff --git a/.docker/php/Dockerfile b/.docker/php74/Dockerfile similarity index 100% rename from .docker/php/Dockerfile rename to .docker/php74/Dockerfile diff --git a/.docker/php/www.conf b/.docker/php74/www.conf similarity index 100% rename from .docker/php/www.conf rename to .docker/php74/www.conf diff --git a/.docker/php82/Dockerfile b/.docker/php82/Dockerfile new file mode 100644 index 0000000..dfb0a5a --- /dev/null +++ b/.docker/php82/Dockerfile @@ -0,0 +1,23 @@ +# ---------------------- +# The FPM base container +# ---------------------- +FROM php:8.2-fpm-alpine AS dev + +# Install build dependencies +RUN apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS + +# Cleanup apk cache and temp files +RUN rm -rf /var/cache/apk/* /tmp/* + +# ---------------------- +# Composer install step +# ---------------------- + +# Get latest Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# ---------------------- +# The FPM production container +# ---------------------- +FROM dev diff --git a/.docker/php82/www.conf b/.docker/php82/www.conf new file mode 100644 index 0000000..39bef0c --- /dev/null +++ b/.docker/php82/www.conf @@ -0,0 +1,85 @@ +; Start a new pool named 'www'. +; the variable $pool can be used in any directive and will be replaced by the +; pool name ('www' here) +[www] + +; Unix user/group of processes +; Note: The user is mandatory. If the group is not set, the default user's group +; will be used. +user = www-data +group = www-data + +; The address on which to accept FastCGI requests. +; Valid syntaxes are: +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on +; a specific port; +; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses +; (IPv6 and IPv4-mapped) on a specific port; +; '/path/to/unix/socket' - to listen on a unix socket. +; Note: This value is mandatory. +listen = 9000 + +; Choose how the process manager will control the number of child processes. +; Possible Values: +; static - a fixed number (pm.max_children) of child processes; +; dynamic - the number of child processes are set dynamically based on the +; following directives. With this process management, there will be +; always at least 1 children. +; pm.max_children - the maximum number of children that can +; be alive at the same time. +; pm.start_servers - the number of children created on startup. +; pm.min_spare_servers - the minimum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is less than this +; number then some children will be created. +; pm.max_spare_servers - the maximum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is greater than this +; number then some children will be killed. +; ondemand - no children are created at startup. Children will be forked when +; new requests will connect. The following parameter are used: +; pm.max_children - the maximum number of children that +; can be alive at the same time. +; pm.process_idle_timeout - The number of seconds after which +; an idle process will be killed. +; Note: This value is mandatory. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. +; This value sets the limit on the number of simultaneous requests that will be +; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. +; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP +; CGI. The below defaults are based on a server without much resources. Don't +; forget to tweak pm.* to fit your needs. +; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' +; Note: This value is mandatory. +pm.max_children = 5 + +; The number of child processes created on startup. +; Note: Used only when pm is set to 'dynamic' +; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 +pm.start_servers = 2 + +; The desired minimum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.min_spare_servers = 1 + +; The desired maximum number of idle server processes. +; Note: Used only when pm is set to 'dynamic' +; Note: Mandatory when pm is set to 'dynamic' +pm.max_spare_servers = 3 + +; The number of seconds after which an idle process will be killed. +; Note: Used only when pm is set to 'ondemand' +; Default Value: 10s +;pm.process_idle_timeout = 10s; + +; The number of requests each child process should execute before respawning. +; This can be useful to work around memory leaks in 3rd party libraries. For +; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. +; Default Value: 0 +;pm.max_requests = 500 diff --git a/LICENSE b/LICENSE index b5b1073..ac00033 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022, Anton Komarev +Copyright (c) 2024, Anton Komarev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 868ab8f..55a20a2 100644 --- a/composer.json +++ b/composer.json @@ -29,16 +29,16 @@ "docs": "https://github.com/cybercog/laravel-clickhouse" }, "require": { - "php": "^8.0", - "illuminate/console": "^9.0|^10.1.3", - "illuminate/contracts": "^9.0|^10.1.3", - "illuminate/filesystem": "^9.0|^10.1.3", - "illuminate/support": "^9.0|^10.1.3", + "php": "^7.4|^8.0", + "illuminate/console": "^8.0|^9.0|^10.1.3", + "illuminate/contracts": "^8.0|^9.0|^10.1.3", + "illuminate/filesystem": "^8.0|^9.0|^10.1.3", + "illuminate/support": "^8.0|^9.0|^10.1.3", "smi2/phpclickhouse": "^1.4" }, "require-dev": { "orchestra/testbench": "^7.0|^8.0", - "phpunit/phpunit": "^9.6" + "phpunit/phpunit": "^9.6|^10.0" }, "autoload": { "psr-4": { diff --git a/config/clickhouse.php b/config/clickhouse.php index e6ee97d..531fc0d 100644 --- a/config/clickhouse.php +++ b/config/clickhouse.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + declare(strict_types=1); return [ diff --git a/docker-compose.yml b/docker-compose.yml index f4ca3ad..ba1c81c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,35 @@ version: "3.9" services: - app: - container_name: laravel-clickhouse-app - image: laravel-clickhouse-app + php74: + container_name: laravel-clickhouse-php74 + image: laravel-clickhouse-php74 build: context: ./ - dockerfile: ./.docker/php/Dockerfile + dockerfile: ./.docker/php74/Dockerfile restart: unless-stopped depends_on: - clickhouse working_dir: /app volumes: - ./:/app - - ./.docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro + - ./.docker/php74/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro + networks: + - laravel-clickhouse + + php82: + container_name: laravel-clickhouse-php82 + image: laravel-clickhouse-php82 + build: + context: ./ + dockerfile: ./.docker/php82/Dockerfile + restart: unless-stopped + depends_on: + - clickhouse + working_dir: /app + volumes: + - ./:/app + - ./.docker/php82/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro networks: - laravel-clickhouse diff --git a/src/ClickhouseServiceProvider.php b/src/ClickhouseServiceProvider.php index e09fafd..e8ab959 100644 --- a/src/ClickhouseServiceProvider.php +++ b/src/ClickhouseServiceProvider.php @@ -1,7 +1,7 @@ * diff --git a/src/ConsoleCommand/ClickhouseMigrateCommand.php b/src/ConsoleCommand/ClickhouseMigrateCommand.php index c5878b0..d00d552 100644 --- a/src/ConsoleCommand/ClickhouseMigrateCommand.php +++ b/src/ConsoleCommand/ClickhouseMigrateCommand.php @@ -1,7 +1,7 @@ * @@ -58,7 +58,7 @@ public function handle( private function getStep(): int { - return (int)$this->option('step'); + return intval($this->option('step')); } private function getMigrationsDirectoryPath(): string diff --git a/src/ConsoleCommand/MakeClickhouseMigrationCommand.php b/src/ConsoleCommand/MakeClickhouseMigrationCommand.php index 2f27725..4a6afd0 100644 --- a/src/ConsoleCommand/MakeClickhouseMigrationCommand.php +++ b/src/ConsoleCommand/MakeClickhouseMigrationCommand.php @@ -1,7 +1,7 @@ * @@ -24,9 +24,7 @@ final class MakeClickhouseMigrationCommand extends Command { private MigrationCreator $creator; - private Composer $composer; - private AppConfigRepositoryInterface $appConfigRepository; protected $description = 'Create a new ClickHouse migration file'; diff --git a/src/Exception/ClickhouseConfigException.php b/src/Exception/ClickhouseConfigException.php index ba4fa35..c9920d3 100644 --- a/src/Exception/ClickhouseConfigException.php +++ b/src/Exception/ClickhouseConfigException.php @@ -1,7 +1,7 @@ * @@ -17,5 +17,4 @@ final class ClickhouseConfigException extends Exception { - // } diff --git a/src/Factory/ClickhouseClientFactory.php b/src/Factory/ClickhouseClientFactory.php index 6de2319..da8ead7 100644 --- a/src/Factory/ClickhouseClientFactory.php +++ b/src/Factory/ClickhouseClientFactory.php @@ -1,7 +1,7 @@ * diff --git a/src/Migration/AbstractClickhouseMigration.php b/src/Migration/AbstractClickhouseMigration.php index 1c679b4..91beed6 100644 --- a/src/Migration/AbstractClickhouseMigration.php +++ b/src/Migration/AbstractClickhouseMigration.php @@ -1,7 +1,7 @@ * @@ -20,7 +20,6 @@ abstract class AbstractClickhouseMigration { protected ?Client $clickhouseClient; - protected string $databaseName; public function __construct( diff --git a/src/Migration/MigrationCreator.php b/src/Migration/MigrationCreator.php index f7eab86..78f7a14 100644 --- a/src/Migration/MigrationCreator.php +++ b/src/Migration/MigrationCreator.php @@ -1,7 +1,7 @@ * @@ -17,8 +17,7 @@ class MigrationCreator { - protected Filesystem $filesystem; - + private Filesystem $filesystem; private ?string $migrationStubFilePath; public function __construct( diff --git a/src/Migration/MigrationRepository.php b/src/Migration/MigrationRepository.php index 39aff4d..5b22e2f 100644 --- a/src/Migration/MigrationRepository.php +++ b/src/Migration/MigrationRepository.php @@ -1,7 +1,7 @@ * @@ -18,9 +18,8 @@ final class MigrationRepository { - protected Client $client; - - protected string $table; + private Client $client; + private string $table; public function __construct( Client $client, @@ -37,13 +36,13 @@ public function createMigrationRegistryTable(): Statement { return $this->client->write( << $this->table, @@ -58,8 +57,8 @@ public function all(): array { $rows = $this->client->select( << $this->table, @@ -78,9 +77,9 @@ public function latest(): array { $rows = $this->client->select( << $this->table, @@ -100,8 +99,8 @@ public function getLastBatchNumber(): int return $this->client ->select( << $this->table, @@ -128,8 +127,8 @@ public function total(): int { return (int)$this->client->select( << $this->table, @@ -141,7 +140,7 @@ public function exists(): bool { return (bool)$this->client->select( << $this->table, @@ -158,10 +157,10 @@ public function find( ): ?array { return $this->client->select( << $this->table, diff --git a/src/Migration/Migrator.php b/src/Migration/Migrator.php index 5dd1b10..ce564d4 100644 --- a/src/Migration/Migrator.php +++ b/src/Migration/Migrator.php @@ -1,7 +1,7 @@ * @@ -28,10 +28,8 @@ final class Migrator { private Client $client; - - protected MigrationRepository $repository; - - protected Filesystem $filesystem; + private MigrationRepository $repository; + private Filesystem $filesystem; public function __construct( Client $client, diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index f1b2ffe..6b3c21a 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -1,7 +1,7 @@ * diff --git a/tests/Factory/ClickhouseClientFactoryTest.php b/tests/Factory/ClickhouseClientFactoryTest.php index b1aa0e6..2e044a9 100644 --- a/tests/Factory/ClickhouseClientFactoryTest.php +++ b/tests/Factory/ClickhouseClientFactoryTest.php @@ -1,7 +1,7 @@ *