Skip to content

Added operation helper #214

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

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
"autoload": {
"psr-4": {
"DragonCode\\LaravelDeployOperations\\": "src/"
}
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
Binary file added docs/images/operation_helper_class.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/operation_helper_class_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/operations_helper_function.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/operations_helper_function_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions docs/snippets/with_operation_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;

use function DragonCode\LaravelDeployOperations\operation;

return new class extends Migration {
public function withOperation(): string
{
return operation('foo/2022_10_14_000002_test2');
}
};
12 changes: 12 additions & 0 deletions docs/topics/operation-helper.topic
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@

<code-block lang="bash" src="operations_helper.sh" include-lines="2" />
</chapter>

<chapter title="Laravel Idea support" id="laravel_idea_support">
<p>
If you are using
<a href="https://www.jetbrains.com/phpstorm/">JetBrains PhpStorm</a>
with the
<a href="https://laravel-idea.com">Laravel Idea</a> plugin installed,
you can use the <code>operation</code> function to autocomplete.
</p>

<img src="operation_helper_class.png" alt="operation helper" />
</chapter>
</topic>
18 changes: 18 additions & 0 deletions docs/topics/running-operations.topic
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,23 @@
When the <code>%artisan% migrate:rollback</code> console command is called,
the operation will call the <code>down</code> method if it exists in the operation file.
</p>

<chapter title="Laravel Idea support" id="laravel_idea_support">
<p>
If you are using
<a href="https://www.jetbrains.com/phpstorm/">JetBrains PhpStorm</a>
with the
<a href="https://laravel-idea.com">Laravel Idea</a> plugin installed,
then autocomplete will be available to you:
</p>
<p>
To avoid entering file names manually, you can use the <code>deploy_operation</code> helper function.
All it does is to suggest IDE paths to operation files with recursive search.
</p>

<code-block lang="php" src="with_operation_helper.php" include-lines="7-" />

<img src="operations_helper_function.png" alt="operation helper"/>
</chapter>
</chapter>
</topic>
3 changes: 3 additions & 0 deletions ide.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"methodNames": [
"run"
],
"functionFqn": [
"DragonCode\\LaravelDeployOperations\\operation"
],
"place": "parameter",
"parameters": [
1
Expand Down
12 changes: 12 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelDeployOperations;

if (! function_exists('\DragonCode\LaravelDeployOperations\operation')) {
function operation(string $filename): string
{
return $filename;
}
}
4 changes: 2 additions & 2 deletions tests/Commands/OperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,9 @@ public function testViaMigrationMethod(): void
])->assertSuccessful();

$this->assertDatabaseCount($table, 1);
$this->assertDatabaseCount($this->table, 0);
$this->assertDatabaseCount($this->table, 1);
$this->assertDatabaseOperationDoesntLike($this->table, 'custom');
$this->assertDatabaseOperationDoesntLike($this->table, 'invoke');
$this->assertDatabaseOperationHas($this->table, 'invoke');
$this->assertDatabaseOperationDoesntLike($this->table, 'up_down');
$this->assertDatabaseOperationDoesntLike($table, 'custom', column: 'value');
$this->assertDatabaseOperationHas($table, 'invoke', column: 'value');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Illuminate\Database\Migrations\Migration;

use function DragonCode\LaravelDeployOperations\operation;

return new class extends Migration {
public function up(): void {}

public function down(): void {}

public function withOperation(): string
{
return '2025_03_31_234251_invoke';
return operation('2025_03_31_234251_invoke');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use Illuminate\Database\Migrations\Migration;

use function DragonCode\LaravelDeployOperations\operation;

return new class extends Migration {
public function up(): void {}

public function down(): void {}

public function withOperation(): string
{
return '2025_03_31_234312_up_down';
return operation('2025_03_31_234312_up_down');
}
};