From ed8bd4bc0ae09229760240ff348e5005d665dd06 Mon Sep 17 00:00:00 2001 From: Veselov Pavel Date: Mon, 12 Aug 2019 01:26:11 +0300 Subject: [PATCH 1/5] add draft commit (definiton for routines) --- src/.meta.php | 4 ++ src/Schema/Blueprint.php | 20 ++++++++ .../Builders/Routines/FunctionBuilder.php | 11 +++++ .../Builders/Routines/TriggerBuilder.php | 11 +++++ src/Schema/Definitions/FunctionDefinition.php | 35 ++++++++++++++ .../Functions/ArgumentDefinition.php | 22 +++++++++ .../Functions/ExecutionDefinition.php | 17 +++++++ .../Functions/SecurityDefinition.php | 16 +++++++ .../Definitions/Functions/SetDefinition.php | 17 +++++++ .../Functions/StabilityDefinition.php | 18 ++++++++ src/Schema/Definitions/TriggerDefinition.php | 32 +++++++++++++ .../Triggers/DeferrableDefinition.php | 16 +++++++ .../Triggers/ExecuteDefinition.php | 16 +++++++ .../Definitions/Triggers/ForDefinition.php | 17 +++++++ .../Triggers/ReferencingDefinition.php | 16 +++++++ .../Triggers/RelationDefinition.php | 14 ++++++ src/Schema/Grammars/PostgresGrammar.php | 10 ++++ src/TriggerHelper.php | 46 +++++++++++++++++++ .../Functional/Helpers/RoutineAssertions.php | 9 ++++ tests/Functional/Schema/CreateRoutineTest.php | 30 ++++++++++++ tests/Unit/Schema/Blueprint/RoutineTest.php | 34 ++++++++++++++ 21 files changed, 411 insertions(+) create mode 100644 src/Schema/Builders/Routines/FunctionBuilder.php create mode 100644 src/Schema/Builders/Routines/TriggerBuilder.php create mode 100644 src/Schema/Definitions/FunctionDefinition.php create mode 100644 src/Schema/Definitions/Functions/ArgumentDefinition.php create mode 100644 src/Schema/Definitions/Functions/ExecutionDefinition.php create mode 100644 src/Schema/Definitions/Functions/SecurityDefinition.php create mode 100644 src/Schema/Definitions/Functions/SetDefinition.php create mode 100644 src/Schema/Definitions/Functions/StabilityDefinition.php create mode 100644 src/Schema/Definitions/TriggerDefinition.php create mode 100644 src/Schema/Definitions/Triggers/DeferrableDefinition.php create mode 100644 src/Schema/Definitions/Triggers/ExecuteDefinition.php create mode 100644 src/Schema/Definitions/Triggers/ForDefinition.php create mode 100644 src/Schema/Definitions/Triggers/ReferencingDefinition.php create mode 100644 src/Schema/Definitions/Triggers/RelationDefinition.php create mode 100644 src/TriggerHelper.php create mode 100644 tests/Functional/Helpers/RoutineAssertions.php create mode 100644 tests/Functional/Schema/CreateRoutineTest.php create mode 100644 tests/Unit/Schema/Blueprint/RoutineTest.php diff --git a/src/.meta.php b/src/.meta.php index 823ec19..0e45238 100644 --- a/src/.meta.php +++ b/src/.meta.php @@ -6,7 +6,9 @@ use Umbrellio\Postgres\Schema\Definitions\AttachPartitionDefinition; use Umbrellio\Postgres\Schema\Definitions\CheckDefinition; use Umbrellio\Postgres\Schema\Definitions\ExcludeDefinition; + use Umbrellio\Postgres\Schema\Definitions\FunctionDefinition; use Umbrellio\Postgres\Schema\Definitions\LikeDefinition; + use Umbrellio\Postgres\Schema\Definitions\TriggerDefinition; use Umbrellio\Postgres\Schema\Definitions\ViewDefinition; use Umbrellio\Postgres\Schema\Definitions\UniqueDefinition; @@ -21,6 +23,8 @@ * @method ColumnDefinition numeric(string $column, ?int $precision = null, ?int $scale = null) * @method ExcludeDefinition exclude($columns, ?string $index = null) * @method CheckDefinition check($columns, ?string $index = null) + * @method FunctionDefinition createFunction(string $name) + * @method TriggerDefinition createTrigger(string $name) */ class Blueprint { diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index a87ae37..2b94e27 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -11,10 +11,14 @@ 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\Builders\Routines\FunctionBuilder; +use Umbrellio\Postgres\Schema\Builders\Routines\TriggerBuilder; use Umbrellio\Postgres\Schema\Definitions\AttachPartitionDefinition; use Umbrellio\Postgres\Schema\Definitions\CheckDefinition; use Umbrellio\Postgres\Schema\Definitions\ExcludeDefinition; +use Umbrellio\Postgres\Schema\Definitions\FunctionDefinition; use Umbrellio\Postgres\Schema\Definitions\LikeDefinition; +use Umbrellio\Postgres\Schema\Definitions\TriggerDefinition; use Umbrellio\Postgres\Schema\Definitions\UniqueDefinition; use Umbrellio\Postgres\Schema\Definitions\ViewDefinition; @@ -121,6 +125,22 @@ public function createView(string $view, string $select, bool $materialize = fal return $this->addCommand('createView', compact('view', 'select', 'materialize')); } + /** + * @return TriggerDefinition + */ + public function createTrigger(string $name): Fluent + { + return $this->addExtendedCommand(TriggerBuilder::class, 'createTrigger', compact('name')); + } + + /** + * @return FunctionDefinition + */ + public function createFunction(string $name): Fluent + { + return $this->addExtendedCommand(FunctionBuilder::class, 'createFunction', compact('name')); + } + public function dropView(string $view): Fluent { return $this->addCommand('dropView', compact('view')); diff --git a/src/Schema/Builders/Routines/FunctionBuilder.php b/src/Schema/Builders/Routines/FunctionBuilder.php new file mode 100644 index 0000000..2fa7471 --- /dev/null +++ b/src/Schema/Builders/Routines/FunctionBuilder.php @@ -0,0 +1,11 @@ +wrapTable($command->get('view')); diff --git a/src/TriggerHelper.php b/src/TriggerHelper.php new file mode 100644 index 0000000..4308dca --- /dev/null +++ b/src/TriggerHelper.php @@ -0,0 +1,46 @@ + 0) { + $declare = 'DECLARE '; + foreach ($params as $param => $type) { + $declare .= "\n {$param} {$type};"; + } + $declare .= "\n"; + } + $statements[] = " + CREATE FUNCTION {$name}() RETURNS trigger AS \${$name}\$ + {$declare} + BEGIN + {$sql} + RETURN NEW; + END; + \${$name}\$ LANGUAGE plpgsql + "; + $statements[] = " + CREATE TRIGGER {$name} {$event} ON {$tableName} + FOR EACH ROW EXECUTE PROCEDURE {$name}() + "; + return $statements; + } + + public function dropStatements(string $name, string $tableName): array + { + $statements[] = 'DROP TRIGGER IF EXISTS ' . $name . ' ON ' . $tableName; + $statements[] = 'DROP FUNCTION IF EXISTS ' . $name; + return $statements; + } +} diff --git a/tests/Functional/Helpers/RoutineAssertions.php b/tests/Functional/Helpers/RoutineAssertions.php new file mode 100644 index 0000000..7123503 --- /dev/null +++ b/tests/Functional/Helpers/RoutineAssertions.php @@ -0,0 +1,9 @@ +createFunction('test_function') + ->security()->definer() + ->stability()->leakProof(true) + ->with('test') + ->window(); + }); + + $this->assertTrue(true); + } +} diff --git a/tests/Unit/Schema/Blueprint/RoutineTest.php b/tests/Unit/Schema/Blueprint/RoutineTest.php new file mode 100644 index 0000000..7159000 --- /dev/null +++ b/tests/Unit/Schema/Blueprint/RoutineTest.php @@ -0,0 +1,34 @@ +initializeMock(static::TABLE); + } + + /** @test */ + public function createFunction(): void + { + $this->assertTrue(true); + + $this->blueprint + ->createFunction('test_function') + ->security()->definer() + ->stability()->leakProof(true) + ->with('test') + ->window(); + } +} From c0a7afd2aa2296f20ea0edb0a6e8d9956ed46a2a Mon Sep 17 00:00:00 2001 From: Veselov Pavel Date: Mon, 12 Aug 2019 13:54:57 +0300 Subject: [PATCH 2/5] refactor & add missing definitions --- src/.meta.php | 25 +++--- src/Compilers/CreateFunctionCompiler.php | 17 +++++ src/Compilers/CreateProcedureCompiler.php | 17 +++++ src/Compilers/CreateTriggerCompiler.php | 17 +++++ src/Compilers/DropFunctionCompiler.php | 17 +++++ src/Compilers/DropProcedureCompiler.php | 17 +++++ src/Compilers/DropTriggerCompiler.php | 17 +++++ src/Schema/Blueprint.php | 76 ++++++++++++++----- .../Routines/CreateFunctionBuilder.php | 11 +++ .../Routines/CreateProcedureBuilder.php | 11 +++ .../Routines/CreateTriggerBuilder.php | 11 +++ ...gerBuilder.php => DropFunctionBuilder.php} | 2 +- .../Routines/DropProcedureBuilder.php | 11 +++ ...tionBuilder.php => DropTriggerBuilder.php} | 2 +- src/Schema/Definitions/FunctionDefinition.php | 35 --------- .../Functions/ArgumentDefinition.php | 22 ------ .../Functions/ExecutionDefinition.php | 17 ----- .../Functions/SecurityDefinition.php | 16 ---- .../Definitions/Functions/SetDefinition.php | 17 ----- .../Functions/StabilityDefinition.php | 18 ----- .../{ => Indexes}/CheckDefinition.php | 2 +- .../{ => Indexes}/ExcludeDefinition.php | 2 +- .../{ => Indexes}/UniqueDefinition.php | 2 +- .../DropRoutineArgumentDefinition.php | 16 ++++ .../Routines/DropRoutineDefinition.php | 18 +++++ .../Functions/CreateFunctionDefinition.php | 27 +++++++ .../Functions/DropFunctionDefinition.php | 15 ++++ .../Functions/ExecutionDefinition.php | 16 ++++ .../Functions/FunctionArgumentDefinition.php | 21 +++++ .../Functions/FunctionSecurityDefinition.php | 15 ++++ .../Functions/FunctionSetDefinition.php | 16 ++++ .../Functions/StabilityDefinition.php | 17 +++++ .../Procedures/CreateProcedureDefinition.php | 19 +++++ .../Procedures/DropProcedureDefinition.php | 15 ++++ .../ProcedureArgumentDefinition.php | 20 +++++ .../ProcedureDropArgumentDefinition.php | 16 ++++ .../ProcedureSecurityDefinition.php | 15 ++++ .../Procedures/ProcedureSetDefinition.php | 16 ++++ .../Routines/RoutineDefinition.php | 17 +++++ .../Triggers/CreateTriggerDefinition.php | 25 ++++++ .../Triggers/DeferrableDefinition.php | 15 ++++ .../Triggers/DropTriggerDefinition.php | 18 +++++ .../Routines/Triggers/EventDefinition.php | 17 +++++ .../Triggers/EventPointDefinition.php | 16 ++++ .../Routines/Triggers/ExecuteDefinition.php | 15 ++++ .../Routines/Triggers/ForDefinition.php | 16 ++++ .../Triggers/ReferencingDefinition.php | 15 ++++ .../Triggers/RelationDefinition.php | 2 +- .../AttachPartitionDefinition.php | 2 +- .../{ => Tables}/LikeDefinition.php | 2 +- src/Schema/Definitions/TriggerDefinition.php | 32 -------- .../Triggers/DeferrableDefinition.php | 16 ---- .../Triggers/ExecuteDefinition.php | 16 ---- .../Definitions/Triggers/ForDefinition.php | 17 ----- .../Triggers/ReferencingDefinition.php | 16 ---- .../{ => Views}/ViewDefinition.php | 2 +- src/Schema/Grammars/PostgresGrammar.php | 40 +++++++++- src/TriggerHelper.php | 46 ----------- tests/Functional/Schema/CreateRoutineTest.php | 14 ++-- tests/Unit/Schema/Blueprint/RoutineTest.php | 41 ++++++++-- 60 files changed, 724 insertions(+), 320 deletions(-) create mode 100644 src/Compilers/CreateFunctionCompiler.php create mode 100644 src/Compilers/CreateProcedureCompiler.php create mode 100644 src/Compilers/CreateTriggerCompiler.php create mode 100644 src/Compilers/DropFunctionCompiler.php create mode 100644 src/Compilers/DropProcedureCompiler.php create mode 100644 src/Compilers/DropTriggerCompiler.php create mode 100644 src/Schema/Builders/Routines/CreateFunctionBuilder.php create mode 100644 src/Schema/Builders/Routines/CreateProcedureBuilder.php create mode 100644 src/Schema/Builders/Routines/CreateTriggerBuilder.php rename src/Schema/Builders/Routines/{TriggerBuilder.php => DropFunctionBuilder.php} (75%) create mode 100644 src/Schema/Builders/Routines/DropProcedureBuilder.php rename src/Schema/Builders/Routines/{FunctionBuilder.php => DropTriggerBuilder.php} (75%) delete mode 100644 src/Schema/Definitions/FunctionDefinition.php delete mode 100644 src/Schema/Definitions/Functions/ArgumentDefinition.php delete mode 100644 src/Schema/Definitions/Functions/ExecutionDefinition.php delete mode 100644 src/Schema/Definitions/Functions/SecurityDefinition.php delete mode 100644 src/Schema/Definitions/Functions/SetDefinition.php delete mode 100644 src/Schema/Definitions/Functions/StabilityDefinition.php rename src/Schema/Definitions/{ => Indexes}/CheckDefinition.php (71%) rename src/Schema/Definitions/{ => Indexes}/ExcludeDefinition.php (87%) rename src/Schema/Definitions/{ => Indexes}/UniqueDefinition.php (92%) create mode 100644 src/Schema/Definitions/Routines/DropRoutineArgumentDefinition.php create mode 100644 src/Schema/Definitions/Routines/DropRoutineDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/CreateFunctionDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/DropFunctionDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/ExecutionDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/FunctionArgumentDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/FunctionSecurityDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/FunctionSetDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/StabilityDefinition.php create mode 100644 src/Schema/Definitions/Routines/Procedures/CreateProcedureDefinition.php create mode 100644 src/Schema/Definitions/Routines/Procedures/DropProcedureDefinition.php create mode 100644 src/Schema/Definitions/Routines/Procedures/ProcedureArgumentDefinition.php create mode 100644 src/Schema/Definitions/Routines/Procedures/ProcedureDropArgumentDefinition.php create mode 100644 src/Schema/Definitions/Routines/Procedures/ProcedureSecurityDefinition.php create mode 100644 src/Schema/Definitions/Routines/Procedures/ProcedureSetDefinition.php create mode 100644 src/Schema/Definitions/Routines/RoutineDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/CreateTriggerDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/DeferrableDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/DropTriggerDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/EventDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/EventPointDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/ExecuteDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/ForDefinition.php create mode 100644 src/Schema/Definitions/Routines/Triggers/ReferencingDefinition.php rename src/Schema/Definitions/{ => Routines}/Triggers/RelationDefinition.php (72%) rename src/Schema/Definitions/{ => Tables}/AttachPartitionDefinition.php (74%) rename src/Schema/Definitions/{ => Tables}/LikeDefinition.php (72%) delete mode 100644 src/Schema/Definitions/TriggerDefinition.php delete mode 100644 src/Schema/Definitions/Triggers/DeferrableDefinition.php delete mode 100644 src/Schema/Definitions/Triggers/ExecuteDefinition.php delete mode 100644 src/Schema/Definitions/Triggers/ForDefinition.php delete mode 100644 src/Schema/Definitions/Triggers/ReferencingDefinition.php rename src/Schema/Definitions/{ => Views}/ViewDefinition.php (74%) delete mode 100644 src/TriggerHelper.php diff --git a/src/.meta.php b/src/.meta.php index 0e45238..31eff57 100644 --- a/src/.meta.php +++ b/src/.meta.php @@ -3,14 +3,15 @@ namespace Illuminate\Database\Schema { 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\FunctionDefinition; - use Umbrellio\Postgres\Schema\Definitions\LikeDefinition; - use Umbrellio\Postgres\Schema\Definitions\TriggerDefinition; - 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 AttachPartitionDefinition attachPartition(string $partition) @@ -23,8 +24,12 @@ * @method ColumnDefinition numeric(string $column, ?int $precision = null, ?int $scale = null) * @method ExcludeDefinition exclude($columns, ?string $index = null) * @method CheckDefinition check($columns, ?string $index = null) - * @method FunctionDefinition createFunction(string $name) - * @method TriggerDefinition createTrigger(string $name) + * @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) */ class Blueprint { diff --git a/src/Compilers/CreateFunctionCompiler.php b/src/Compilers/CreateFunctionCompiler.php new file mode 100644 index 0000000..5221628 --- /dev/null +++ b/src/Compilers/CreateFunctionCompiler.php @@ -0,0 +1,17 @@ +addCommand('createView', compact('view', 'select', 'materialize')); } /** - * @return TriggerDefinition + * @return CreateTriggerDefinition */ - public function createTrigger(string $name): Fluent + public function createTrigger(string $name) { - return $this->addExtendedCommand(TriggerBuilder::class, 'createTrigger', compact('name')); + return $this->addExtendedCommand(CreateTriggerBuilder::class, 'createTrigger', compact('name')); } /** - * @return FunctionDefinition + * @return CreateFunctionDefinition */ - public function createFunction(string $name): Fluent + public function createFunction(string $name) { - return $this->addExtendedCommand(FunctionBuilder::class, 'createFunction', compact('name')); + return $this->addExtendedCommand(CreateFunctionBuilder::class, 'createFunction', compact('name')); + } + + /** + * @return CreateProcedureDefinition + */ + public function createProcedure(string $name) + { + return $this->addExtendedCommand(CreateProcedureBuilder::class, 'createProcedure', compact('name')); + } + + /** + * @return DropFunctionDefinition + */ + public function dropFunction(string $name) + { + return $this->addExtendedCommand(DropFunctionBuilder::class, 'dropFunction', compact('name')); + } + + /** + * @return DropProcedureDefinition + */ + public function dropProcedure(string $name) + { + return $this->addExtendedCommand(DropProcedureBuilder::class, 'dropProcedure', compact('name')); } public function dropView(string $view): Fluent @@ -146,6 +178,14 @@ public function dropView(string $view): Fluent 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')); + } + /** * Almost like 'decimal' type, but can be with variable precision (by default) */ diff --git a/src/Schema/Builders/Routines/CreateFunctionBuilder.php b/src/Schema/Builders/Routines/CreateFunctionBuilder.php new file mode 100644 index 0000000..eeee20c --- /dev/null +++ b/src/Schema/Builders/Routines/CreateFunctionBuilder.php @@ -0,0 +1,11 @@ + 0) { - $declare = 'DECLARE '; - foreach ($params as $param => $type) { - $declare .= "\n {$param} {$type};"; - } - $declare .= "\n"; - } - $statements[] = " - CREATE FUNCTION {$name}() RETURNS trigger AS \${$name}\$ - {$declare} - BEGIN - {$sql} - RETURN NEW; - END; - \${$name}\$ LANGUAGE plpgsql - "; - $statements[] = " - CREATE TRIGGER {$name} {$event} ON {$tableName} - FOR EACH ROW EXECUTE PROCEDURE {$name}() - "; - return $statements; - } - - public function dropStatements(string $name, string $tableName): array - { - $statements[] = 'DROP TRIGGER IF EXISTS ' . $name . ' ON ' . $tableName; - $statements[] = 'DROP FUNCTION IF EXISTS ' . $name; - return $statements; - } -} diff --git a/tests/Functional/Schema/CreateRoutineTest.php b/tests/Functional/Schema/CreateRoutineTest.php index f661998..920c39c 100644 --- a/tests/Functional/Schema/CreateRoutineTest.php +++ b/tests/Functional/Schema/CreateRoutineTest.php @@ -18,13 +18,17 @@ class CreateRoutineTest extends FunctionalTestCase public function createFunction(): void { Schema::create('test_table', function (Blueprint $table) { - $table->createFunction('test_function') - ->security()->definer() - ->stability()->leakProof(true) - ->with('test') - ->window(); + $table->createFunction('test_function'); + $table->createProcedure('test_function'); + $table->createTrigger('test_function'); }); $this->assertTrue(true); + + Schema::table('test_table', function (Blueprint $table) { + $table->dropFunction('test_function'); + $table->dropProcedure('test_function'); + $table->dropTrigger('test_function'); + }); } } diff --git a/tests/Unit/Schema/Blueprint/RoutineTest.php b/tests/Unit/Schema/Blueprint/RoutineTest.php index 7159000..105c664 100644 --- a/tests/Unit/Schema/Blueprint/RoutineTest.php +++ b/tests/Unit/Schema/Blueprint/RoutineTest.php @@ -22,13 +22,42 @@ protected function setUp(): void /** @test */ public function createFunction(): void { + $this->blueprint->createFunction('test_function'); $this->assertTrue(true); + } + + /** @test */ + public function createProcedure(): void + { + $this->blueprint->createProcedure('test_procedure'); + $this->assertTrue(true); + } + + /** @test */ + public function createTrigger(): void + { + $this->blueprint->createTrigger('test_trigger'); + $this->assertTrue(true); + } + + /** @test */ + public function dropFunction(): void + { + $this->blueprint->dropFunction('test_function'); + $this->assertTrue(true); + } + + /** @test */ + public function dropProcedure(): void + { + $this->blueprint->dropProcedure('test_procedure'); + $this->assertTrue(true); + } - $this->blueprint - ->createFunction('test_function') - ->security()->definer() - ->stability()->leakProof(true) - ->with('test') - ->window(); + /** @test */ + public function dropTrigger(): void + { + $this->blueprint->dropTrigger('test_trigger'); + $this->assertTrue(true); } } From 4c0897a398b9700c4abe9ac057704865db5bae5d Mon Sep 17 00:00:00 2001 From: Korben Dallas Date: Fri, 4 Dec 2020 20:32:27 +0300 Subject: [PATCH 3/5] draft commit for definitions --- .travis.yml | 4 +- composer.json | 3 +- .../Routines/CreateFunctionBuilder.php | 38 +++++++++++++++++++ .../Routines/Functions/ExecutionBuilder.php | 25 ++++++++++++ .../Functions/FunctionArgumentBuilder.php | 29 ++++++++++++++ .../Functions/FunctionSecurityBuilder.php | 25 ++++++++++++ .../Routines/Functions/FunctionSetBuilder.php | 25 ++++++++++++ .../Routines/Functions/ParallelBuilder.php | 25 ++++++++++++ .../Routines/Functions/StabilityBuilder.php | 25 ++++++++++++ .../Arguments/ArgumentDefinition.php | 18 +++++++++ .../Functions/CreateFunctionDefinition.php | 4 +- .../Functions/FunctionArgumentDefinition.php | 6 +-- .../Routines/Functions/ParallelDefinition.php | 16 ++++++++ 13 files changed, 236 insertions(+), 7 deletions(-) create mode 100644 src/Schema/Builders/Routines/Functions/ExecutionBuilder.php create mode 100644 src/Schema/Builders/Routines/Functions/FunctionArgumentBuilder.php create mode 100644 src/Schema/Builders/Routines/Functions/FunctionSecurityBuilder.php create mode 100644 src/Schema/Builders/Routines/Functions/FunctionSetBuilder.php create mode 100644 src/Schema/Builders/Routines/Functions/ParallelBuilder.php create mode 100644 src/Schema/Builders/Routines/Functions/StabilityBuilder.php create mode 100644 src/Schema/Definitions/Routines/Functions/Arguments/ArgumentDefinition.php create mode 100644 src/Schema/Definitions/Routines/Functions/ParallelDefinition.php diff --git a/.travis.yml b/.travis.yml index 49767e9..8b08de9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ after_success: matrix: fast_finish: true allow_failures: - - php: "7.4snapshot" + - php: "7.4" include: - stage: Test php: "7.2" @@ -107,7 +107,7 @@ matrix: before_script: - bash ./tests/travis/install-postgres-11.sh - stage: Test - php: "7.4snapshot" + php: "7.4" env: DB=pgsql DOCKER_POSTGRES=yes POSTGRESQL_VERSION=11.0 sudo: required services: diff --git a/composer.json b/composer.json index 6ab341d..b14b1e0 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "umbrellio/laravel-pg-extensions", "type": "library", + "description": "This is package for new features for Postgres in Laravel Migrations", "minimum-stability": "stable", "authors": [ { @@ -9,7 +10,7 @@ } ], "require": { - "php": "^7.2", + "php": "7.*", "doctrine/dbal": "^2.9", "laravel/framework": "^5.8" }, diff --git a/src/Schema/Builders/Routines/CreateFunctionBuilder.php b/src/Schema/Builders/Routines/CreateFunctionBuilder.php index eeee20c..d80972a 100644 --- a/src/Schema/Builders/Routines/CreateFunctionBuilder.php +++ b/src/Schema/Builders/Routines/CreateFunctionBuilder.php @@ -5,7 +5,45 @@ namespace Umbrellio\Postgres\Schema\Builders\Routines; use Illuminate\Support\Fluent; +use Umbrellio\Postgres\Schema\Builders\Indexes\Unique\UniquePartialBuilder; +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; + } } diff --git a/src/Schema/Builders/Routines/Functions/ExecutionBuilder.php b/src/Schema/Builders/Routines/Functions/ExecutionBuilder.php new file mode 100644 index 0000000..f3c0efc --- /dev/null +++ b/src/Schema/Builders/Routines/Functions/ExecutionBuilder.php @@ -0,0 +1,25 @@ +builder = $builder; + + parent::__construct($attributes); + } + + public function __call($method, $parameters) + { + parent::__call($method, $parameters); + + return $this->builder; + } +} diff --git a/src/Schema/Builders/Routines/Functions/FunctionArgumentBuilder.php b/src/Schema/Builders/Routines/Functions/FunctionArgumentBuilder.php new file mode 100644 index 0000000..184048e --- /dev/null +++ b/src/Schema/Builders/Routines/Functions/FunctionArgumentBuilder.php @@ -0,0 +1,29 @@ +builder = $builder; + + parent::__construct($attributes); + } + + public function __call($method, $parameters) + { + if (in_array($method, ["in", "out", "inout", "variadic"], true)) { + $this->attributes['mode'] = $method; + } else { + parent::__call($method, $parameters); + } + + return $this->builder; + } +} diff --git a/src/Schema/Builders/Routines/Functions/FunctionSecurityBuilder.php b/src/Schema/Builders/Routines/Functions/FunctionSecurityBuilder.php new file mode 100644 index 0000000..b5c6383 --- /dev/null +++ b/src/Schema/Builders/Routines/Functions/FunctionSecurityBuilder.php @@ -0,0 +1,25 @@ +builder = $builder; + + parent::__construct($attributes); + } + + public function __call($method, $parameters) + { + parent::__call($method, $parameters); + + return $this->builder; + } +} diff --git a/src/Schema/Builders/Routines/Functions/FunctionSetBuilder.php b/src/Schema/Builders/Routines/Functions/FunctionSetBuilder.php new file mode 100644 index 0000000..dff30a5 --- /dev/null +++ b/src/Schema/Builders/Routines/Functions/FunctionSetBuilder.php @@ -0,0 +1,25 @@ +builder = $builder; + + parent::__construct($attributes); + } + + public function __call($method, $parameters) + { + parent::__call($method, $parameters); + + return $this->builder; + } +} diff --git a/src/Schema/Builders/Routines/Functions/ParallelBuilder.php b/src/Schema/Builders/Routines/Functions/ParallelBuilder.php new file mode 100644 index 0000000..548b0a0 --- /dev/null +++ b/src/Schema/Builders/Routines/Functions/ParallelBuilder.php @@ -0,0 +1,25 @@ +builder = $builder; + + parent::__construct($attributes); + } + + public function __call($method, $parameters) + { + parent::__call($method, $parameters); + + return $this->builder; + } +} diff --git a/src/Schema/Builders/Routines/Functions/StabilityBuilder.php b/src/Schema/Builders/Routines/Functions/StabilityBuilder.php new file mode 100644 index 0000000..a6a9e2f --- /dev/null +++ b/src/Schema/Builders/Routines/Functions/StabilityBuilder.php @@ -0,0 +1,25 @@ +builder = $builder; + + parent::__construct($attributes); + } + + public function __call($method, $parameters) + { + parent::__call($method, $parameters); + + return $this->builder; + } +} diff --git a/src/Schema/Definitions/Routines/Functions/Arguments/ArgumentDefinition.php b/src/Schema/Definitions/Routines/Functions/Arguments/ArgumentDefinition.php new file mode 100644 index 0000000..b5c72e5 --- /dev/null +++ b/src/Schema/Definitions/Routines/Functions/Arguments/ArgumentDefinition.php @@ -0,0 +1,18 @@ + Date: Sun, 20 Dec 2020 04:22:55 +0300 Subject: [PATCH 4/5] linter fixes --- .github/labeler.yml | 2 +- tests/Unit/Schema/Blueprint/RoutineTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index a6091c1..2c3a1e5 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -21,7 +21,7 @@ type:indexes: - "src/Schema/Definitions/CheckDefinition.php" - "src/Schema/Definitions/ExcludeDefinition.php" - "src/Schema/Definitions/UniqueDefinition.php" - - + type:routines: - "src/Compilers/Routines/**/*" - "src/Schema/Builders/Routines/**/*" diff --git a/tests/Unit/Schema/Blueprint/RoutineTest.php b/tests/Unit/Schema/Blueprint/RoutineTest.php index 581d27e..cc85622 100644 --- a/tests/Unit/Schema/Blueprint/RoutineTest.php +++ b/tests/Unit/Schema/Blueprint/RoutineTest.php @@ -16,6 +16,7 @@ class RoutineTest extends TestCase protected function setUp(): void { parent::setUp(); + $this->initializeMock(static::TABLE); } From 71b815b4a429250849e3944602f9213eafc689fd Mon Sep 17 00:00:00 2001 From: Korben Date: Fri, 3 May 2024 11:38:33 +0200 Subject: [PATCH 5/5] lint fix --- build/logs/clover.xml | 1303 +++++++++-------- tests.sh | 13 +- tests/Functional/Schema/CreateRoutineTest.php | 9 +- tests/Unit/Schema/Blueprint/RoutineTest.php | 25 +- 4 files changed, 725 insertions(+), 625 deletions(-) diff --git a/build/logs/clover.xml b/build/logs/clover.xml index 0f79eb6..1a6094b 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,6 +1,6 @@ - - + + @@ -31,180 +31,213 @@ - - - - - - - - + + + + + + + + - + - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + - - - + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - + + + + + + + + @@ -262,247 +295,167 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - + - + - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -514,29 +467,29 @@ - - - + + + - - - + + + - + - - - - - + + + + + @@ -544,50 +497,166 @@ - - - + + + - - - + + + + - - - + + + + + + + + + - + + + + - - - - - - - - - - - - + + + + + - - + + - + - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -595,202 +664,254 @@ - - + + - - + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -838,6 +959,6 @@ - + diff --git a/tests.sh b/tests.sh index c5a4636..ded3648 100755 --- a/tests.sh +++ b/tests.sh @@ -8,15 +8,4 @@ sed -e "s/\${USERNAME}/postgres/" \ phpunit.xml.dist > phpunit.xml COMPOSER_MEMORY_LIMIT=-1 composer update composer lint -php vendor/bin/phpunit -c phpunit.xml --migrate-configuration -if [ "x$EXCLUDE_GROUP" != "x" ]; then - php -d pcov.directory='.' vendor/bin/phpunit \ - --exclude-group $EXCLUDE_GROUP \ - --coverage-html build \ - --coverage-text -else - php -d pcov.directory='.' vendor/bin/phpunit \ - --exclude-group WithoutSchema,forPHP7 \ - --coverage-html build \ - --coverage-text -fi +php -d xdebug.mode=coverage -d memory_limit=-1 vendor/bin/phpunit --coverage-html build --coverage-text diff --git a/tests/Functional/Schema/CreateRoutineTest.php b/tests/Functional/Schema/CreateRoutineTest.php index 9985a09..1c616f7 100644 --- a/tests/Functional/Schema/CreateRoutineTest.php +++ b/tests/Functional/Schema/CreateRoutineTest.php @@ -6,17 +6,18 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Schema; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\Postgres\Schema\Blueprint; use Umbrellio\Postgres\Tests\Functional\Helpers\RoutineAssertions; use Umbrellio\Postgres\Tests\FunctionalTestCase; class CreateRoutineTest extends FunctionalTestCase { - use DatabaseTransactions, RoutineAssertions; + use DatabaseTransactions; - /** - * @test - */ + use RoutineAssertions; + + #[Test] public function createFunction(): void { Schema::create('test_table', function (Blueprint $table) { diff --git a/tests/Unit/Schema/Blueprint/RoutineTest.php b/tests/Unit/Schema/Blueprint/RoutineTest.php index cc85622..0bbc2c3 100644 --- a/tests/Unit/Schema/Blueprint/RoutineTest.php +++ b/tests/Unit/Schema/Blueprint/RoutineTest.php @@ -4,6 +4,7 @@ namespace Umbrellio\Postgres\Unit\Schema\Blueprint; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\Postgres\Tests\TestCase; use Umbrellio\Postgres\Tests\Unit\Helpers\BlueprintAssertions; @@ -20,54 +21,42 @@ protected function setUp(): void $this->initializeMock(static::TABLE); } - /** - * @test - */ + #[Test] public function createFunction(): void { $this->blueprint->createFunction('test_function'); $this->assertTrue(true); } - /** - * @test - */ + #[Test] public function createProcedure(): void { $this->blueprint->createProcedure('test_procedure'); $this->assertTrue(true); } - /** - * @test - */ + #[Test] public function createTrigger(): void { $this->blueprint->createTrigger('test_trigger'); $this->assertTrue(true); } - /** - * @test - */ + #[Test] public function dropFunction(): void { $this->blueprint->dropFunction('test_function'); $this->assertTrue(true); } - /** - * @test - */ + #[Test] public function dropProcedure(): void { $this->blueprint->dropProcedure('test_procedure'); $this->assertTrue(true); } - /** - * @test - */ + #[Test] public function dropTrigger(): void { $this->blueprint->dropTrigger('test_trigger');