Skip to content

Commit

Permalink
Merge pull request #17 from denizgolbas/main
Browse files Browse the repository at this point in the history
Update PostgresGrammar.php
  • Loading branch information
ArdaKaraderi authored Feb 18, 2023
2 parents 1948cb4 + ef6b06e commit e1cc2e1
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PostgresGrammar extends IlluminatePostgresGrammar
/**
* Compile a create table command with its range partitions.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
Expand All @@ -27,7 +27,7 @@ public function compileCreateRangePartitioned(Blueprint $blueprint, Fluent $comm
/**
* Compile a create table partition command for a range partitioned table.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
Expand All @@ -45,7 +45,7 @@ public function compileCreateRangePartition(Blueprint $blueprint, Fluent $comman
/**
* Compile an attach partition command for a range partitioned table.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
Expand All @@ -62,40 +62,40 @@ public function compileAttachRangePartition(Blueprint $blueprint, Fluent $comman
/**
* Compile a create table command with its list partitions.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
public function compileCreateListPartitioned(Blueprint $blueprint, Fluent $command)
{
return array_values(array_filter(array_merge([sprintf('create table %s (%s) partition by list(%s)',
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
)], $this->compileAutoIncrementStartingValues($blueprint))));
);
}

/**
* Compile a create table partition command for a list partitioned table.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
public function compileCreateListPartition(Blueprint $blueprint, Fluent $command)
{
return array_values(array_filter(array_merge([sprintf('create table %s_%s partition of %s for values in (\'%s\')',
return sprintf('create table %s_%s partition of %s for values in (\'%s\')',
str_replace("\"", "", $this->wrapTable($blueprint)),
$blueprint->suffixForPartition,
str_replace("\"", "", $this->wrapTable($blueprint)),
$blueprint->listPartitionValue,
)], $this->compileAutoIncrementStartingValues($blueprint))));
);
}

/**
* Compile an attach partition command for a list partitioned table.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
Expand All @@ -111,7 +111,7 @@ public function compileAttachListPartition(Blueprint $blueprint, Fluent $command
/**
* Compile a create table command with its hash partitions.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
Expand All @@ -127,25 +127,26 @@ public function compileCreateHashPartitioned(Blueprint $blueprint, Fluent $comma
/**
* Compile a create table partition command for a hash partitioned table.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
public function compileCreateHashPartition(Blueprint $blueprint, Fluent $command)
{
return array_values(array_filter(array_merge([sprintf('create table %s_%s partition of %s for values with (modulus %s, remainder %s)',
return sprintf('create table %s_%s partition of %s for values with (modulus %s, remainder %s)',
str_replace("\"", "", $this->wrapTable($blueprint)),
$blueprint->suffixForPartition,
str_replace("\"", "", $this->wrapTable($blueprint)),
$blueprint->hashModulus,
$blueprint->hashRemainder,
)], $this->compileAutoIncrementStartingValues($blueprint))));
$blueprint->hashRemainder
);

}

/**
* Compile an attach partition command for a hash partitioned table.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
Expand All @@ -161,12 +162,12 @@ public function compileAttachHashPartition(Blueprint $blueprint, Fluent $command

/**
* Get a list of all partitioned tables in the Database.
* @param string $table
* @param string $table
* @return string
*/
public function compileGetPartitions(string $table)
{
return sprintf("SELECT inhrelid::regclass as tables
return sprintf("SELECT inhrelid::regclass as tables
FROM pg_catalog.pg_inherits
WHERE inhparent = '%s'::regclass;",
$table,
Expand Down Expand Up @@ -203,7 +204,7 @@ public function compileGetAllHashPartitionedTables()
/**
* Compile a detach query for a partitioned table.
*
* @param Blueprint $blueprint
* @param Blueprint $blueprint
* @param Fluent $command
* @return array
*/
Expand Down

0 comments on commit e1cc2e1

Please sign in to comment.