Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feature/triggers #28

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1,303 changes: 712 additions & 591 deletions build/logs/clover.xml

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions src/.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class Schema {

use Closure;
use Illuminate\Support\Fluent;
use Umbrellio\Postgres\Schema\Definitions\AttachPartitionDefinition;
use Umbrellio\Postgres\Schema\Definitions\CheckDefinition;
use Umbrellio\Postgres\Schema\Definitions\ExcludeDefinition;
use Umbrellio\Postgres\Schema\Definitions\LikeDefinition;
use Umbrellio\Postgres\Schema\Definitions\ViewDefinition;
use Umbrellio\Postgres\Schema\Definitions\UniqueDefinition;
use Umbrellio\Postgres\Schema\Definitions\Tables\AttachPartitionDefinition;
use Umbrellio\Postgres\Schema\Definitions\Indexes\CheckDefinition;
use Umbrellio\Postgres\Schema\Definitions\Indexes\ExcludeDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Functions\CreateFunctionDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Procedures\CreateProcedureDefinition;
use Umbrellio\Postgres\Schema\Definitions\Tables\LikeDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Triggers\CreateTriggerDefinition;
use Umbrellio\Postgres\Schema\Definitions\Views\ViewDefinition;
use Umbrellio\Postgres\Schema\Definitions\Indexes\UniqueDefinition;

/**
* @method __construct($table, Closure $callback = null, $prefix = '')
Expand All @@ -38,6 +41,12 @@ class Schema {
* @method ColumnDefinition daterange(string $column)
* @method ExcludeDefinition exclude($columns, ?string $index = null)
* @method CheckDefinition check($columns, ?string $index = null)
* @method CreateFunctionDefinition createFunction(string $name)
* @method CreateProcedureDefinition createProcedure(string $name)
* @method CreateTriggerDefinition createTrigger(string $name)
* @method Fluent dropProcedure(string $name)
* @method Fluent dropFunction(string $name)
* @method Fluent dropTrigger(string $name, bool $dropDepends = false)
* @method string getTable()
* @method ColumnDefinition|Fluent addColumn($type, $name, array $parameters = [])
*
Expand Down
17 changes: 17 additions & 0 deletions src/Compilers/CreateFunctionCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Compilers;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;
use Umbrellio\Postgres\Schema\Builders\Routines\CreateFunctionBuilder;

class CreateFunctionCompiler
{
public static function compile(Grammar $grammar, Blueprint $blueprint, CreateFunctionBuilder $command): array

Check notice on line 13 in src/Compilers/CreateFunctionCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateFunctionCompiler.php#L13

The parameter ``$grammar`` is not used and could be removed.

Check notice on line 13 in src/Compilers/CreateFunctionCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateFunctionCompiler.php#L13

The parameter ``$command`` is not used and could be removed.

Check notice on line 13 in src/Compilers/CreateFunctionCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateFunctionCompiler.php#L13

The parameter ``$blueprint`` is not used and could be removed.
{
return [];
}
}
17 changes: 17 additions & 0 deletions src/Compilers/CreateProcedureCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Compilers;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;
use Umbrellio\Postgres\Schema\Builders\Routines\CreateProcedureBuilder;

class CreateProcedureCompiler
{
public static function compile(Grammar $grammar, Blueprint $blueprint, CreateProcedureBuilder $command): array

Check notice on line 13 in src/Compilers/CreateProcedureCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateProcedureCompiler.php#L13

The parameter ``$grammar`` is not used and could be removed.

Check notice on line 13 in src/Compilers/CreateProcedureCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateProcedureCompiler.php#L13

The parameter ``$command`` is not used and could be removed.

Check notice on line 13 in src/Compilers/CreateProcedureCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateProcedureCompiler.php#L13

The parameter ``$blueprint`` is not used and could be removed.
{
return [];
}
}
17 changes: 17 additions & 0 deletions src/Compilers/CreateTriggerCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Compilers;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;
use Umbrellio\Postgres\Schema\Builders\Routines\CreateTriggerBuilder;

class CreateTriggerCompiler
{
public static function compile(Grammar $grammar, Blueprint $blueprint, CreateTriggerBuilder $command): array

Check notice on line 13 in src/Compilers/CreateTriggerCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateTriggerCompiler.php#L13

The parameter ``$grammar`` is not used and could be removed.

Check notice on line 13 in src/Compilers/CreateTriggerCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateTriggerCompiler.php#L13

The parameter ``$command`` is not used and could be removed.

Check notice on line 13 in src/Compilers/CreateTriggerCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/CreateTriggerCompiler.php#L13

The parameter ``$blueprint`` is not used and could be removed.
{
return [];
}
}
17 changes: 17 additions & 0 deletions src/Compilers/DropFunctionCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Compilers;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;
use Umbrellio\Postgres\Schema\Builders\Routines\DropFunctionBuilder;

class DropFunctionCompiler
{
public static function compile(Grammar $grammar, Blueprint $blueprint, DropFunctionBuilder $command): string

Check notice on line 13 in src/Compilers/DropFunctionCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropFunctionCompiler.php#L13

The parameter ``$grammar`` is not used and could be removed.

Check notice on line 13 in src/Compilers/DropFunctionCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropFunctionCompiler.php#L13

The parameter ``$command`` is not used and could be removed.

Check notice on line 13 in src/Compilers/DropFunctionCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropFunctionCompiler.php#L13

The parameter ``$blueprint`` is not used and could be removed.
{
return '';
}
}
17 changes: 17 additions & 0 deletions src/Compilers/DropProcedureCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Compilers;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;
use Umbrellio\Postgres\Schema\Builders\Routines\DropProcedureBuilder;

class DropProcedureCompiler
{
public static function compile(Grammar $grammar, Blueprint $blueprint, DropProcedureBuilder $command): string

Check notice on line 13 in src/Compilers/DropProcedureCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropProcedureCompiler.php#L13

The parameter ``$grammar`` is not used and could be removed.

Check notice on line 13 in src/Compilers/DropProcedureCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropProcedureCompiler.php#L13

The parameter ``$command`` is not used and could be removed.

Check notice on line 13 in src/Compilers/DropProcedureCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropProcedureCompiler.php#L13

The parameter ``$blueprint`` is not used and could be removed.
{
return '';
}
}
17 changes: 17 additions & 0 deletions src/Compilers/DropTriggerCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Compilers;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;
use Umbrellio\Postgres\Schema\Builders\Routines\DropTriggerBuilder;

class DropTriggerCompiler
{
public static function compile(Grammar $grammar, Blueprint $blueprint, DropTriggerBuilder $command): array

Check notice on line 13 in src/Compilers/DropTriggerCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropTriggerCompiler.php#L13

The parameter ``$grammar`` is not used and could be removed.

Check notice on line 13 in src/Compilers/DropTriggerCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropTriggerCompiler.php#L13

The parameter ``$command`` is not used and could be removed.

Check notice on line 13 in src/Compilers/DropTriggerCompiler.php

View check run for this annotation

Scrutinizer / Inspection

src/Compilers/DropTriggerCompiler.php#L13

The parameter ``$blueprint`` is not used and could be removed.
{
return [];
}
}
74 changes: 67 additions & 7 deletions src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@
use Umbrellio\Postgres\Schema\Builders\Constraints\Check\CheckBuilder;
use Umbrellio\Postgres\Schema\Builders\Constraints\Exclude\ExcludeBuilder;
use Umbrellio\Postgres\Schema\Builders\Indexes\Unique\UniqueBuilder;
use Umbrellio\Postgres\Schema\Definitions\AttachPartitionDefinition;
use Umbrellio\Postgres\Schema\Definitions\CheckDefinition;
use Umbrellio\Postgres\Schema\Definitions\ExcludeDefinition;
use Umbrellio\Postgres\Schema\Definitions\LikeDefinition;
use Umbrellio\Postgres\Schema\Definitions\UniqueDefinition;
use Umbrellio\Postgres\Schema\Definitions\ViewDefinition;
use Umbrellio\Postgres\Schema\Builders\Routines\CreateFunctionBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\CreateProcedureBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\CreateTriggerBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\DropFunctionBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\DropProcedureBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\DropTriggerBuilder;
use Umbrellio\Postgres\Schema\Definitions\Indexes\CheckDefinition;
use Umbrellio\Postgres\Schema\Definitions\Indexes\ExcludeDefinition;
use Umbrellio\Postgres\Schema\Definitions\Indexes\UniqueDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Functions\CreateFunctionDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Functions\DropFunctionDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Procedures\CreateProcedureDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Procedures\DropProcedureDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Triggers\CreateTriggerDefinition;
use Umbrellio\Postgres\Schema\Definitions\Routines\Triggers\DropTriggerDefinition;
use Umbrellio\Postgres\Schema\Definitions\Tables\AttachPartitionDefinition;
use Umbrellio\Postgres\Schema\Definitions\Tables\LikeDefinition;
use Umbrellio\Postgres\Schema\Definitions\Views\ViewDefinition;
use Umbrellio\Postgres\Schema\Types\DateRangeType;
use Umbrellio\Postgres\Schema\Types\TsRangeType;
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
Expand Down Expand Up @@ -130,11 +142,51 @@
* @codeCoverageIgnore
* @return ViewDefinition|Fluent
*/
public function createView(string $view, string $select, bool $materialize = false): Fluent
public function createView(string $view, string $select, bool $materialize = false)
{
return $this->addCommand('createView', compact('view', 'select', 'materialize'));
}

/**
* @return CreateTriggerDefinition
*/
public function createTrigger(string $name)
{
return $this->addExtendedCommand(CreateTriggerBuilder::class, 'createTrigger', compact('name'));

Check failure on line 155 in src/Schema/Blueprint.php

View check run for this annotation

Scrutinizer / Inspection

src/Schema/Blueprint.php#L155

The expression ``return $this->addExtendedCommand(Umbrellio\Postgres\Schema\Builders\Routines\CreateTriggerBuilder::class, 'createTrigger', compact('name'))`` returns the type ``Umbrellio\Postgres\Schema\Builders\Routines\CreateTriggerBuilder`` which is incompatible with the documented return type ``Umbrellio\Postgres\Schema\Definitions\Routines\Triggers\CreateTriggerDefinition``.
}

/**
* @return CreateFunctionDefinition
*/
public function createFunction(string $name)
{
return $this->addExtendedCommand(CreateFunctionBuilder::class, 'createFunction', compact('name'));

Check failure on line 163 in src/Schema/Blueprint.php

View check run for this annotation

Scrutinizer / Inspection

src/Schema/Blueprint.php#L163

The expression ``return $this->addExtendedCommand(Umbrellio\Postgres\Schema\Builders\Routines\CreateFunctionBuilder::class, 'createFunction', compact('name'))`` returns the type ``Umbrellio\Postgres\Schema\Builders\Routines\CreateFunctionBuilder`` which is incompatible with the documented return type ``Umbrellio\Postgres\Schema\Definitions\Routines\Functions\CreateFunctionDefinition``.
}

/**
* @return CreateProcedureDefinition
*/
public function createProcedure(string $name)
{
return $this->addExtendedCommand(CreateProcedureBuilder::class, 'createProcedure', compact('name'));

Check failure on line 171 in src/Schema/Blueprint.php

View check run for this annotation

Scrutinizer / Inspection

src/Schema/Blueprint.php#L171

The expression ``return $this->addExtendedCommand(Umbrellio\Postgres\Schema\Builders\Routines\CreateProcedureBuilder::class, 'createProcedure', compact('name'))`` returns the type ``Umbrellio\Postgres\Schema\Builders\Routines\CreateProcedureBuilder`` which is incompatible with the documented return type ``Umbrellio\Postgres\Schema\Definitions\Routines\Procedures\CreateProcedureDefinition``.
}

/**
* @return DropFunctionDefinition
*/
public function dropFunction(string $name)
{
return $this->addExtendedCommand(DropFunctionBuilder::class, 'dropFunction', compact('name'));

Check failure on line 179 in src/Schema/Blueprint.php

View check run for this annotation

Scrutinizer / Inspection

src/Schema/Blueprint.php#L179

The expression ``return $this->addExtendedCommand(Umbrellio\Postgres\Schema\Builders\Routines\DropFunctionBuilder::class, 'dropFunction', compact('name'))`` returns the type ``Umbrellio\Postgres\Schema\Builders\Routines\DropFunctionBuilder`` which is incompatible with the documented return type ``Umbrellio\Postgres\Schema\Definitions\Routines\Functions\DropFunctionDefinition``.
}

/**
* @return DropProcedureDefinition
*/
public function dropProcedure(string $name)
{
return $this->addExtendedCommand(DropProcedureBuilder::class, 'dropProcedure', compact('name'));

Check failure on line 187 in src/Schema/Blueprint.php

View check run for this annotation

Scrutinizer / Inspection

src/Schema/Blueprint.php#L187

The expression ``return $this->addExtendedCommand(Umbrellio\Postgres\Schema\Builders\Routines\DropProcedureBuilder::class, 'dropProcedure', compact('name'))`` returns the type ``Umbrellio\Postgres\Schema\Builders\Routines\DropProcedureBuilder`` which is incompatible with the documented return type ``Umbrellio\Postgres\Schema\Definitions\Routines\Procedures\DropProcedureDefinition``.
}

/**
* @codeCoverageIgnore
*/
Expand All @@ -143,6 +195,14 @@
return $this->addCommand('dropView', compact('view'));
}

/**
* @return DropTriggerDefinition
*/
public function dropTrigger(string $name, bool $dropDepends = false)
{
return $this->addExtendedCommand(DropTriggerBuilder::class, 'dropTrigger', compact('name', 'dropDepends'));

Check failure on line 203 in src/Schema/Blueprint.php

View check run for this annotation

Scrutinizer / Inspection

src/Schema/Blueprint.php#L203

The expression ``return $this->addExtendedCommand(Umbrellio\Postgres\Schema\Builders\Routines\DropTriggerBuilder::class, 'dropTrigger', compact('name', 'dropDepends'))`` returns the type ``Umbrellio\Postgres\Schema\Builders\Routines\DropTriggerBuilder`` which is incompatible with the documented return type ``Umbrellio\Postgres\Schema\Definitions\Routines\Triggers\DropTriggerDefinition``.
}

/**
* Almost like 'decimal' type, but can be with variable precision (by default)
*
Expand Down
48 changes: 48 additions & 0 deletions src/Schema/Builders/Routines/CreateFunctionBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Schema\Builders\Routines;

use Illuminate\Support\Fluent;
use Umbrellio\Postgres\Schema\Builders\Routines\Functions\ExecutionBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\Functions\FunctionArgumentBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\Functions\FunctionSecurityBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\Functions\FunctionSetBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\Functions\ParallelBuilder;
use Umbrellio\Postgres\Schema\Builders\Routines\Functions\StabilityBuilder;

class CreateFunctionBuilder extends Fluent
{
public function __call($method, $parameters)
{
switch ($method) {
case 'arg':
$command = new FunctionArgumentBuilder($this);
$this->attributes[$method] = call_user_func_array([$command, $method], $parameters);
break;
case 'stability':
$command = new StabilityBuilder($this);
$this->attributes[$method] = call_user_func_array([$command, $method], $parameters);
break;
case 'execution':
$command = new ExecutionBuilder($this);
break;
case 'security':
$command = new FunctionSecurityBuilder($this);
break;
case 'set':
$command = new FunctionSetBuilder($this);
break;
case 'parallel':
$command = new ParallelBuilder($this);
break;
default:
$command = $this;
}

parent::__call($method, $parameters);

return $command ?? $this;
}
}
11 changes: 11 additions & 0 deletions src/Schema/Builders/Routines/CreateProcedureBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Schema\Builders\Routines;

use Illuminate\Support\Fluent;

class CreateProcedureBuilder extends Fluent
{
}
11 changes: 11 additions & 0 deletions src/Schema/Builders/Routines/CreateTriggerBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Schema\Builders\Routines;

use Illuminate\Support\Fluent;

class CreateTriggerBuilder extends Fluent
{
}
11 changes: 11 additions & 0 deletions src/Schema/Builders/Routines/DropFunctionBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Schema\Builders\Routines;

use Illuminate\Support\Fluent;

class DropFunctionBuilder extends Fluent
{
}
11 changes: 11 additions & 0 deletions src/Schema/Builders/Routines/DropProcedureBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Schema\Builders\Routines;

use Illuminate\Support\Fluent;

class DropProcedureBuilder extends Fluent
{
}
11 changes: 11 additions & 0 deletions src/Schema/Builders/Routines/DropTriggerBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Schema\Builders\Routines;

use Illuminate\Support\Fluent;

class DropTriggerBuilder extends Fluent
{
}
27 changes: 27 additions & 0 deletions src/Schema/Builders/Routines/Functions/ExecutionBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Umbrellio\Postgres\Schema\Builders\Routines\Functions;

use Illuminate\Support\Fluent;
use Umbrellio\Postgres\Schema\Builders\Routines\CreateFunctionBuilder;

class ExecutionBuilder extends Fluent
{
private $builder;

public function __construct(CreateFunctionBuilder $builder, $attributes = [])
{
$this->builder = $builder;

parent::__construct($attributes);
}

public function __call($method, $parameters)
{
parent::__call($method, $parameters);

return $this->builder;
}
}
Loading
Loading