From 92f6feb92468dde5d9f0d502b46554612961bd6d Mon Sep 17 00:00:00 2001 From: Arda Karaderi Date: Sat, 8 Jun 2024 14:03:15 +0300 Subject: [PATCH] Laravel 11.x Support (#33) * Updated dependencies to support Laravel 11. * Updates on the Grammar. * Minor update. * Test bench version updated to 9 on tests. * Updated the security policy. * Some code quality improvements. --- .github/SECURITY.md | 5 +- .github/workflows/run-tests.yml | 8 +- composer.json | 48 ++++----- src/Commands/ListTablePartitionsCommand.php | 7 ++ src/Database/Schema/Blueprint.php | 85 ++++++++-------- src/Database/Schema/Builder.php | 28 +++--- .../Schema/Grammars/PostgresGrammar.php | 97 +++++++++---------- src/Support/Facades/Schema.php | 49 +++++++--- 8 files changed, 180 insertions(+), 147 deletions(-) diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 5a6ba45..3c39a4e 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -11,8 +11,9 @@ If you discover a security vulnerability within the package, please send an emai Here is the list of project versions that are currently being supported with security updates. | Version | Supported | -| ------- | ------------------ | +|---------| ------------------ | | 1.x.x | :x: | | 2.x.x | :x: | -| 3.x.x | :white_check_mark: | +| 3.x.x | :x: | | 4.x.x | :white_check_mark: | +| 5.x.x | :white_check_mark: | diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index bb9cb2e..d9ece21 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,12 +13,12 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.1] - laravel: [10.*] + php: [8.2] + laravel: [11.*] stability: [prefer-lowest, prefer-stable] include: - - laravel: 10.* - testbench: 8.* + - laravel: 11.* + testbench: 9.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 33122f0..a3aebc3 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,14 @@ { "name": "orptech/laravel-migration-partition", - "description": "Laravel extensions for creating migrations with partitions.", + "description": "Laravel extensions that extends Illuminate to enable partitioned table creation within Laravel migrations.", "keywords": [ - "ORPTech", + "ORPtech", "laravel", + "migrations", + "database", + "postgres", + "postgre", + "psql", "laravel-migration-partition" ], "homepage": "https://github.com/orptech/laravel-migration-partition", @@ -12,31 +17,30 @@ { "name": "Arda Karaderi", "email": "info@orptech.com", - "role": "Developer" + "role": "Software Engineer" } ], "require": { - "php": "^8.1", - "doctrine/dbal": "^3.4", - "illuminate/contracts": "^10.0", - "illuminate/database": "^10.0", - "illuminate/support": "^10.0", - "illuminate/console":"^10.0", - "illuminate/filesystem":"^10.0", - "spatie/laravel-package-tools": "^1.13.0" + "php": "^8.2", + "illuminate/contracts": "^11.0", + "illuminate/database": "^11.0", + "illuminate/support": "^11.0", + "illuminate/console":"^11.0", + "illuminate/filesystem":"^11.0", + "spatie/laravel-package-tools": "^1.16.0" }, "require-dev": { - "laravel/pint": "^1.0", - "nunomaduro/collision": "^6.0", - "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^8.0", - "pestphp/pest": "^1.21", - "pestphp/pest-plugin-laravel": "^1.1", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5", - "spatie/laravel-ray": "^1.26" + "laravel/pint": "^1.14", + "nunomaduro/collision": "^8.1.1", + "larastan/larastan": "^2.9", + "orchestra/testbench": "^9.0.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-arch": "^2.7", + "pestphp/pest-plugin-laravel": "^2.3", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpstan/phpstan-phpunit": "^1.3", + "spatie/laravel-ray": "^1.35" }, "autoload": { "psr-4": { diff --git a/src/Commands/ListTablePartitionsCommand.php b/src/Commands/ListTablePartitionsCommand.php index 2fdcea4..8678331 100644 --- a/src/Commands/ListTablePartitionsCommand.php +++ b/src/Commands/ListTablePartitionsCommand.php @@ -21,6 +21,13 @@ class ListTablePartitionsCommand extends Command * * @var string */ + protected $description = 'Lists partitions for a table.'; + + /** + * The target table. + * + * @var string + */ protected string $table; diff --git a/src/Database/Schema/Blueprint.php b/src/Database/Schema/Blueprint.php index e2a83ed..e01447d 100644 --- a/src/Database/Schema/Blueprint.php +++ b/src/Database/Schema/Blueprint.php @@ -3,6 +3,7 @@ namespace ORPTech\MigrationPartition\Database\Schema; use Illuminate\Database\Schema\Blueprint as IlluminateBlueprint; +use Illuminate\Support\Fluent; class Blueprint extends IlluminateBlueprint { @@ -11,98 +12,98 @@ class Blueprint extends IlluminateBlueprint * * @var string */ - public $pkCompositeOne; + public string $pkCompositeOne; /** * Column key two for creating a composite key for range partitioned table. * * @var string */ - public $pkCompositeTwo; + public string $pkCompositeTwo; /** * Partition range key for creating a range partitioned table. * * @var string */ - public $rangeKey; + public string $rangeKey; /** * Partition range key for creating a range partitioned table. * * @var string */ - public $suffixForPartition; + public string $suffixForPartition; /** * Partition range key for creating a range partitioned table. * * @var string */ - public $startDate; + public string $startDate; /** * Partition range key for creating a range partitioned table. * * @var string */ - public $endDate; + public string $endDate; /** * Column key for creating a table with list partition. * * @var string */ - public $listPartitionKey; + public string $listPartitionKey; /** * Column key for creating list partitions. * * @var string */ - public $listPartitionValue; + public string $listPartitionValue; /** * Column key for creating a table with hash partition. * * @var string */ - public $hashPartitionKey; + public string $hashPartitionKey; /** * Hashing modulus for creating a hash partition. * * @var int */ - public $hashModulus; + public int $hashModulus; /** * Hashing reminder for creating a hash partition. * * @var int */ - public $hashRemainder; + public int $hashRemainder; /** * Column key for creating a table with list partition. * * @var string */ - public $partitionTableName; + public string $partitionTableName; /** * List of commands that trigger the creating function. * * @var array */ - private $creators = ['create', 'createRangePartitioned', 'createListPartitioned', 'createHashPartitioned']; + private array $creators = ['create', 'createRangePartitioned', 'createListPartitioned', 'createHashPartitioned']; /** * Determine if the blueprint has a create command. * * @return bool */ - public function creating() + public function creating(): bool { return collect($this->commands)->contains(function ($command) { return in_array($command->name, $this->creators, false); @@ -112,9 +113,9 @@ public function creating() /** * Indicate that the table needs to be created with a range partition. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function createRangePartitioned() + public function createRangePartitioned(): Fluent { return $this->addCommand('createRangePartitioned'); } @@ -122,9 +123,9 @@ public function createRangePartitioned() /** * Create a range partition and attach it to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function createRangePartition() + public function createRangePartition(): Fluent { return $this->addCommand('createRangePartition'); } @@ -132,9 +133,9 @@ public function createRangePartition() /** * Attach a range partition for existing table to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function attachRangePartition() + public function attachRangePartition(): Fluent { return $this->addCommand('attachRangePartition'); } @@ -142,9 +143,9 @@ public function attachRangePartition() /** * Indicate that the table needs to be created with a list partition. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function createListPartitioned() + public function createListPartitioned(): Fluent { return $this->addCommand('createListPartitioned'); } @@ -152,9 +153,9 @@ public function createListPartitioned() /** * Attach a range partition for existing table to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function attachListPartition() + public function attachListPartition(): Fluent { return $this->addCommand('attachListPartition'); } @@ -162,9 +163,9 @@ public function attachListPartition() /** * Create a list partition and attach it to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function createListPartition() + public function createListPartition(): Fluent { return $this->addCommand('createListPartition'); } @@ -172,9 +173,9 @@ public function createListPartition() /** * Indicate that the table needs to be created with a hash partition. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function createHashPartitioned() + public function createHashPartitioned(): Fluent { return $this->addCommand('createHashPartitioned'); } @@ -182,18 +183,18 @@ public function createHashPartitioned() /** * Create a hash partition and attach it to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function createHashPartition() + public function createHashPartition(): Fluent { return $this->addCommand('createHashPartition'); } /** * Attach a range partition for existing table to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function attachHashPartition() + public function attachHashPartition(): Fluent { return $this->addCommand('attachHashPartition'); } @@ -201,9 +202,9 @@ public function attachHashPartition() /** * Create a hash partition and attach it to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function getAllRangePartitionedTables() + public function getAllRangePartitionedTables(): Fluent { return $this->addCommand('getAllRangePartitionedTables'); } @@ -211,9 +212,9 @@ public function getAllRangePartitionedTables() /** * Create a hash partition and attach it to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function getAllHashPartitionedTables() + public function getAllHashPartitionedTables(): Fluent { return $this->addCommand('getAllHashPartitionedTables'); } @@ -221,9 +222,9 @@ public function getAllHashPartitionedTables() /** * Create a hash partition and attach it to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function getAllListPartitionedTables() + public function getAllListPartitionedTables(): Fluent { return $this->addCommand('getAllListPartitionedTables'); } @@ -231,18 +232,18 @@ public function getAllListPartitionedTables() /** * Create a hash partition and attach it to the partitioned table. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function getPartitions() + public function getPartitions(): Fluent { return $this->addCommand('getPartitions'); } /** * Indicate that the table needs to be created with a range partition. * - * @return \Illuminate\Support\Fluent + * @return Fluent */ - public function detachPartition() + public function detachPartition(): Fluent { return $this->addCommand('detachPartition'); } diff --git a/src/Database/Schema/Builder.php b/src/Database/Schema/Builder.php index 9eda967..dc4c65b 100755 --- a/src/Database/Schema/Builder.php +++ b/src/Database/Schema/Builder.php @@ -29,7 +29,7 @@ public function __construct(Connection $connection) * @return void * @throws BindingResolutionException */ - public function createRangePartitioned(string $table, Closure $callback, string $pkCompositeOne, string $pkCompositeTwo, string $rangeKey) + public function createRangePartitioned(string $table, Closure $callback, string $pkCompositeOne, string $pkCompositeTwo, string $rangeKey): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $pkCompositeOne, $pkCompositeTwo, $rangeKey) { $blueprint->createRangePartitioned(); @@ -52,7 +52,7 @@ public function createRangePartitioned(string $table, Closure $callback, string * @return void * @throws BindingResolutionException */ - public function createRangePartition(string $table, Closure $callback, string $suffixForPartition, string $startDate, string $endDate) + public function createRangePartition(string $table, Closure $callback, string $suffixForPartition, string $startDate, string $endDate): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $suffixForPartition, $startDate, $endDate) { $blueprint->createRangePartition(); @@ -75,7 +75,7 @@ public function createRangePartition(string $table, Closure $callback, string $s * @return void * @throws BindingResolutionException */ - public function attachRangePartition(string $table, Closure $callback, string $partitionTableName, string $startDate, string $endDate) + public function attachRangePartition(string $table, Closure $callback, string $partitionTableName, string $startDate, string $endDate): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $partitionTableName, $startDate, $endDate) { $blueprint->attachRangePartition(); @@ -97,7 +97,7 @@ public function attachRangePartition(string $table, Closure $callback, string $p * @return void * @throws BindingResolutionException */ - public function createListPartitioned(string $table, Closure $callback, string $pkCompositeOne, string $pkCompositeTwo, string $listPartitionKey) + public function createListPartitioned(string $table, Closure $callback, string $pkCompositeOne, string $pkCompositeTwo, string $listPartitionKey): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $pkCompositeOne, $pkCompositeTwo, $listPartitionKey) { $blueprint->createListPartitioned(); @@ -119,7 +119,7 @@ public function createListPartitioned(string $table, Closure $callback, string $ * @return void * @throws BindingResolutionException */ - public function createListPartition(string $table, Closure $callback, string $suffixForPartition, string $listPartitionValue) + public function createListPartition(string $table, Closure $callback, string $suffixForPartition, string $listPartitionValue): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $suffixForPartition, $listPartitionValue) { $blueprint->createListPartition(); @@ -140,7 +140,7 @@ public function createListPartition(string $table, Closure $callback, string $su * @return void * @throws BindingResolutionException */ - public function attachListPartition(string $table, Closure $callback, string $partitionTableName, string $listPartitionValue) + public function attachListPartition(string $table, Closure $callback, string $partitionTableName, string $listPartitionValue): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $partitionTableName, $listPartitionValue) { $blueprint->attachListPartition(); @@ -161,7 +161,7 @@ public function attachListPartition(string $table, Closure $callback, string $pa * @return void * @throws BindingResolutionException */ - public function createHashPartitioned(string $table, Closure $callback, string $pkCompositeOne, string $pkCompositeTwo, string $hashPartitionKey) + public function createHashPartitioned(string $table, Closure $callback, string $pkCompositeOne, string $pkCompositeTwo, string $hashPartitionKey): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $pkCompositeOne, $pkCompositeTwo, $hashPartitionKey) { $blueprint->createHashPartitioned(); @@ -184,7 +184,7 @@ public function createHashPartitioned(string $table, Closure $callback, string $ * @return void * @throws BindingResolutionException */ - public function createHashPartition(string $table, Closure $callback, string $suffixForPartition, int $hashModulus, int $hashRemainder) + public function createHashPartition(string $table, Closure $callback, string $suffixForPartition, int $hashModulus, int $hashRemainder): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $suffixForPartition, $hashModulus, $hashRemainder) { $blueprint->createHashPartition(); @@ -206,7 +206,7 @@ public function createHashPartition(string $table, Closure $callback, string $su * @return void * @throws BindingResolutionException */ - public function attachHashPartition(string $table, Closure $callback, string $partitionTableName, int $hashModulus, int $hashRemainder) + public function attachHashPartition(string $table, Closure $callback, string $partitionTableName, int $hashModulus, int $hashRemainder): void { $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $partitionTableName, $hashModulus, $hashRemainder) { $blueprint->attachHashPartition(); @@ -223,7 +223,7 @@ public function attachHashPartition(string $table, Closure $callback, string $pa * @param string $table * @return array */ - public function getPartitions(string $table) + public function getPartitions(string $table): array { return array_column(DB::select($this->grammar->compileGetPartitions($table)), 'tables'); } @@ -233,7 +233,7 @@ public function getPartitions(string $table) * * @return array */ - public function getAllRangePartitionedTables() + public function getAllRangePartitionedTables(): array { return array_column(DB::select($this->grammar->compileGetAllRangePartitionedTables()), 'tables'); } @@ -243,7 +243,7 @@ public function getAllRangePartitionedTables() * * @return array */ - public function getAllListPartitionedTables() + public function getAllListPartitionedTables(): array { return array_column(DB::select($this->grammar->compileGetAllListPartitionedTables()), 'tables'); } @@ -253,7 +253,7 @@ public function getAllListPartitionedTables() * * @return array */ - public function getAllHashPartitionedTables() + public function getAllHashPartitionedTables(): array { return array_column(DB::select($this->grammar->compileGetAllHashPartitionedTables()), 'tables'); } @@ -284,7 +284,7 @@ public function detachPartition(string $table, Closure $callback, string $partit * @return Closure|mixed|object|Blueprint|null * @throws BindingResolutionException */ - protected function createBlueprint($table, Closure $callback = null) + protected function createBlueprint($table, Closure $callback = null): mixed { $prefix = $this->connection->getConfig('prefix_indexes') ? $this->connection->getConfig('prefix') diff --git a/src/Database/Schema/Grammars/PostgresGrammar.php b/src/Database/Schema/Grammars/PostgresGrammar.php index c72b08b..3b3cf2b 100755 --- a/src/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Database/Schema/Grammars/PostgresGrammar.php @@ -15,13 +15,13 @@ class PostgresGrammar extends IlluminatePostgresGrammar * @param Fluent $command * @return array */ - public function compileCreateRangePartitioned(Blueprint $blueprint, Fluent $command) + public function compileCreateRangePartitioned(Blueprint $blueprint, Fluent $command): array { return array_values(array_filter(array_merge([sprintf('create table %s (%s) partition by range (%s)', $this->wrapTable($blueprint), sprintf('%s, %s', implode(', ', $this->getColumns($blueprint)), sprintf('primary key (%s, %s)', $blueprint->pkCompositeOne, $blueprint->pkCompositeTwo)), $blueprint->rangeKey - )], $this->compileAutoIncrementStartingValues($blueprint)))); + )], [$this->compileAutoIncrementStartingValues($blueprint, $command)]))); } /** @@ -31,7 +31,7 @@ public function compileCreateRangePartitioned(Blueprint $blueprint, Fluent $comm * @param Fluent $command * @return array */ - public function compileCreateRangePartition(Blueprint $blueprint, Fluent $command) + public function compileCreateRangePartition(Blueprint $blueprint, Fluent $command): array { return array_values(array_filter(array_merge([sprintf('create table %s_%s partition of %s for values from (\'%s\') to (\'%s\')', str_replace("\"", "", $this->wrapTable($blueprint)), @@ -39,39 +39,39 @@ public function compileCreateRangePartition(Blueprint $blueprint, Fluent $comman str_replace("\"", "", $this->wrapTable($blueprint)), $blueprint->startDate, $blueprint->endDate - )], $this->compileAutoIncrementStartingValues($blueprint)))); + )], [$this->compileAutoIncrementStartingValues($blueprint, $command)]))); } /** - * Compile an attach partition command for a range partitioned table. + * Compile a create table command with its list partitions. * * @param Blueprint $blueprint * @param Fluent $command - * @return array + * @return string */ - public function compileAttachRangePartition(Blueprint $blueprint, Fluent $command) + public function compileCreateListPartitioned(Blueprint $blueprint, Fluent $command): string { - return sprintf('ALTER table %s attach partition %s for values from (\'%s\') to (\'%s\')', - str_replace("\"", "", $this->wrapTable($blueprint)), - $blueprint->partitionTableName, - $blueprint->startDate, - $blueprint->endDate + return sprintf('create table %s (%s) partition by list(%s)', + $this->wrapTable($blueprint), + sprintf('%s, %s', implode(', ', $this->getColumns($blueprint)), sprintf('primary key (%s, %s)', $blueprint->pkCompositeOne, $blueprint->pkCompositeTwo)), + $blueprint->listPartitionKey ); } /** - * Compile a create table command with its list partitions. + * Compile an attach partition command for a range partitioned table. * * @param Blueprint $blueprint * @param Fluent $command - * @return array + * @return string */ - public function compileCreateListPartitioned(Blueprint $blueprint, Fluent $command) + public function compileAttachRangePartition(Blueprint $blueprint, Fluent $command): string { - return sprintf('create table %s (%s) partition by list(%s)', - $this->wrapTable($blueprint), - sprintf('%s, %s', implode(', ', $this->getColumns($blueprint)), sprintf('primary key (%s, %s)', $blueprint->pkCompositeOne, $blueprint->pkCompositeTwo)), - $blueprint->listPartitionKey + return sprintf('ALTER table %s attach partition %s for values from (\'%s\') to (\'%s\')', + str_replace("\"", "", $this->wrapTable($blueprint)), + $blueprint->partitionTableName, + $blueprint->startDate, + $blueprint->endDate ); } @@ -80,9 +80,9 @@ public function compileCreateListPartitioned(Blueprint $blueprint, Fluent $comma * * @param Blueprint $blueprint * @param Fluent $command - * @return array + * @return string */ - public function compileCreateListPartition(Blueprint $blueprint, Fluent $command) + public function compileCreateListPartition(Blueprint $blueprint, Fluent $command): string { return sprintf('create table %s_%s partition of %s for values in (\'%s\')', str_replace("\"", "", $this->wrapTable($blueprint)), @@ -97,9 +97,9 @@ public function compileCreateListPartition(Blueprint $blueprint, Fluent $command * * @param Blueprint $blueprint * @param Fluent $command - * @return array + * @return string */ - public function compileAttachListPartition(Blueprint $blueprint, Fluent $command) + public function compileAttachListPartition(Blueprint $blueprint, Fluent $command): string { return sprintf('alter table %s partition of %s for values in (\'%s\')', str_replace("\"", "", $this->wrapTable($blueprint)), @@ -108,30 +108,14 @@ public function compileAttachListPartition(Blueprint $blueprint, Fluent $command ); } - /** - * Compile a create table command with its hash partitions. - * - * @param Blueprint $blueprint - * @param Fluent $command - * @return array - */ - public function compileCreateHashPartitioned(Blueprint $blueprint, Fluent $command) - { - return array_values(array_filter(array_merge([sprintf('create table %s (%s) partition by hash(%s)', - $this->wrapTable($blueprint), - sprintf('%s, %s', implode(', ', $this->getColumns($blueprint)), sprintf('primary key (%s, %s)', $blueprint->pkCompositeOne, $blueprint->pkCompositeTwo)), - $blueprint->hashPartitionKey - )], $this->compileAutoIncrementStartingValues($blueprint)))); - } - /** * Compile a create table partition command for a hash partitioned table. * * @param Blueprint $blueprint * @param Fluent $command - * @return array + * @return string */ - public function compileCreateHashPartition(Blueprint $blueprint, Fluent $command) + public function compileCreateHashPartition(Blueprint $blueprint, Fluent $command): string { return sprintf('create table %s_%s partition of %s for values with (modulus %s, remainder %s)', str_replace("\"", "", $this->wrapTable($blueprint)), @@ -140,7 +124,22 @@ public function compileCreateHashPartition(Blueprint $blueprint, Fluent $command $blueprint->hashModulus, $blueprint->hashRemainder ); + } + /** + * Compile a create table command with its hash partitions. + * + * @param Blueprint $blueprint + * @param Fluent $command + * @return array + */ + public function compileCreateHashPartitioned(Blueprint $blueprint, Fluent $command): array + { + return array_values(array_filter(array_merge([sprintf('create table %s (%s) partition by hash(%s)', + $this->wrapTable($blueprint), + sprintf('%s, %s', implode(', ', $this->getColumns($blueprint)), sprintf('primary key (%s, %s)', $blueprint->pkCompositeOne, $blueprint->pkCompositeTwo)), + $blueprint->hashPartitionKey + )], [$this->compileAutoIncrementStartingValues($blueprint, $command)]))); } /** @@ -148,9 +147,9 @@ public function compileCreateHashPartition(Blueprint $blueprint, Fluent $command * * @param Blueprint $blueprint * @param Fluent $command - * @return array + * @return string */ - public function compileAttachHashPartition(Blueprint $blueprint, Fluent $command) + public function compileAttachHashPartition(Blueprint $blueprint, Fluent $command): string { return sprintf('alter table %s partition of %s for values with (modulus %s, remainder %s)', str_replace("\"", "", $this->wrapTable($blueprint)), @@ -165,7 +164,7 @@ public function compileAttachHashPartition(Blueprint $blueprint, Fluent $command * @param string $table * @return string */ - public function compileGetPartitions(string $table) + public function compileGetPartitions(string $table): string { return sprintf("SELECT inhrelid::regclass as tables FROM pg_catalog.pg_inherits @@ -178,7 +177,7 @@ public function compileGetPartitions(string $table) * Get all range partitioned tables. * @return string */ - public function compileGetAllRangePartitionedTables() + public function compileGetAllRangePartitionedTables(): string { return "select pg_class.relname as tables from pg_class inner join pg_partitioned_table on pg_class.oid = pg_partitioned_table.partrelid where pg_partitioned_table.partstrat = 'r';"; } @@ -187,7 +186,7 @@ public function compileGetAllRangePartitionedTables() * Get all list partitioned tables. * @return string */ - public function compileGetAllListPartitionedTables() + public function compileGetAllListPartitionedTables(): string { return "select pg_class.relname as tables from pg_class inner join pg_partitioned_table on pg_class.oid = pg_partitioned_table.partrelid where pg_partitioned_table.partstrat = 'l';"; } @@ -196,7 +195,7 @@ public function compileGetAllListPartitionedTables() * Get all hash partitioned tables. * @return string */ - public function compileGetAllHashPartitionedTables() + public function compileGetAllHashPartitionedTables(): string { return "select pg_class.relname as tables from pg_class inner join pg_partitioned_table on pg_class.oid = pg_partitioned_table.partrelid where pg_partitioned_table.partstrat = 'h';"; } @@ -206,9 +205,9 @@ public function compileGetAllHashPartitionedTables() * * @param Blueprint $blueprint * @param Fluent $command - * @return array + * @return string */ - public function compileDetachPartition(Blueprint $blueprint, Fluent $command) + public function compileDetachPartition(Blueprint $blueprint, Fluent $command): string { return sprintf('alter table %s detach partition %s', str_replace("\"", "", $this->wrapTable($blueprint)), diff --git a/src/Support/Facades/Schema.php b/src/Support/Facades/Schema.php index 32a11b6..07e90f2 100755 --- a/src/Support/Facades/Schema.php +++ b/src/Support/Facades/Schema.php @@ -26,27 +26,48 @@ * @method static getPartitions(string $table) * @method static detachPartition(string $table, \Closure $callback, string $partitionTableName) * Default builder methods. - * @method static \Illuminate\Database\Schema\Builder create(string $table, \Closure $callback) - * @method static \Illuminate\Database\Schema\Builder createDatabase(string $name) - * @method static \Illuminate\Database\Schema\Builder disableForeignKeyConstraints() - * @method static \Illuminate\Database\Schema\Builder drop(string $table) - * @method static \Illuminate\Database\Schema\Builder dropDatabaseIfExists(string $name) - * @method static \Illuminate\Database\Schema\Builder dropIfExists(string $table) - * @method static \Illuminate\Database\Schema\Builder enableForeignKeyConstraints() - * @method static \Illuminate\Database\Schema\Builder rename(string $from, string $to) - * @method static \Illuminate\Database\Schema\Builder table(string $table, \Closure $callback) + * @method static void defaultStringLength(int $length) + * @method static void defaultMorphKeyType(string $type) + * @method static void morphUsingUuids() + * @method static void morphUsingUlids() + * @method static bool createDatabase(string $name) + * @method static bool dropDatabaseIfExists(string $name) + * @method static bool hasTable(string $table) + * @method static bool hasView(string $view) + * @method static array getTables() + * @method static array getTableListing() + * @method static array getViews() + * @method static array getTypes() * @method static bool hasColumn(string $table, string $column) * @method static bool hasColumns(string $table, array $columns) - * @method static bool dropColumns(string $table, array $columns) * @method static void whenTableHasColumn(string $table, string $column, \Closure $callback) * @method static void whenTableDoesntHaveColumn(string $table, string $column, \Closure $callback) - * @method static bool hasTable(string $table) - * @method static void defaultStringLength(int $length) + * @method static string getColumnType(string $table, string $column, bool $fullDefinition = false) * @method static array getColumnListing(string $table) - * @method static string getColumnType(string $table, string $column) - * @method static void morphUsingUuids() + * @method static array getColumns(string $table) + * @method static array getIndexes(string $table) + * @method static array getIndexListing(string $table) + * @method static bool hasIndex(string $table, string|array $index, string|null $type = null) + * @method static array getForeignKeys(string $table) + * @method static void table(string $table, \Closure $callback) + * @method static void create(string $table, \Closure $callback) + * @method static void drop(string $table) + * @method static void dropIfExists(string $table) + * @method static void dropColumns(string $table, string|array $columns) + * @method static void dropAllTables() + * @method static void dropAllViews() + * @method static void dropAllTypes() + * @method static void rename(string $from, string $to) + * @method static bool enableForeignKeyConstraints() + * @method static bool disableForeignKeyConstraints() + * @method static mixed withoutForeignKeyConstraints(\Closure $callback) * @method static \Illuminate\Database\Connection getConnection() * @method static \Illuminate\Database\Schema\Builder setConnection(\Illuminate\Database\Connection $connection) + * @method static void blueprintResolver(\Closure $resolver) + * @method static void macro(string $name, object|callable $macro) + * @method static void mixin(object $mixin, bool $replace = true) + * @method static bool hasMacro(string $name) + * @method static void flushMacros() * * @see \ORPTech\MigrationPartition\Database\Schema\Builder */