Skip to content

Commit

Permalink
Merge pull request #158 from TheDragonCode/6.x
Browse files Browse the repository at this point in the history
Database transaction settings moved to configuration file
  • Loading branch information
andrey-helldar authored May 21, 2024
2 parents 6affd26 + b3b7e90 commit 7a967a8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
19 changes: 19 additions & 0 deletions config/deploy-operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@

'table' => 'operations',

/*
|--------------------------------------------------------------------------
| Database Transations
|--------------------------------------------------------------------------
|
| This setting defines the rules for working with database transactions.
| This specifies a common value for all operations, but you can override this
| value directly in the class of the operation itself.
*/

'transactions' => [
// | Determines whether the use of database transactions is enabled.

'enabled' => false,

// | The number of attempts to execute a request within a transaction before throwing an error.
'attempts' => 1,
],

/*
|--------------------------------------------------------------------------
| Operations Path
Expand Down
14 changes: 10 additions & 4 deletions docs/how-to-use/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,20 @@ use DragonCode\LaravelDeployOperations\Operation;

return new class extends Operation
{
protected bool $transactions = true;

protected int $transactionAttempts = 3;

public function __invoke(): void
{
// some code
}

public function enabledTransactions(): bool
{
return true;
}

public function transactionAttempts(): int
{
return 4;
}
};
```

Expand Down
16 changes: 14 additions & 2 deletions docs/prologue/upgrade-guide/6.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

## Minor-Impact Changes

- [Changed file location](#changed-file-location)
- [Changed directory location](#changed-directory-location)
- [Removed database transaction properties](#removed-database-transaction-properties)

## Low-Impact Changes

Expand Down Expand Up @@ -136,10 +137,21 @@ class Names
}
```

## Changed file location
## Changed directory location

File storage directory changed to `operations` from `actions`.

## Removed database transaction properties

The following properties have been removed:

- `$transactions`
- `$transactionAttempts`

Instead, you can use the previously available `enabledTransactions` and `transactionAttempts` methods.

The default setting for these parameters has been moved to the `transactions` section of the configuration file.

## Stub name changed

If you published a stub file, then you also need to rename it from `stubs/action.stub` to `stubs/deploy-operation.stub`
Expand Down
14 changes: 2 additions & 12 deletions src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ abstract class Operation
*/
protected bool $once = true;

/**
* Determines a call to database transactions.
*
* By default, false.
*/
protected bool $transactions = false;

/** The number of attempts to execute a request within a transaction before throwing an error. */
protected int $transactionAttempts = 1;

/**
* Determines which environment to run on.
*/
Expand Down Expand Up @@ -64,15 +54,15 @@ public function isOnce(): bool
*/
public function enabledTransactions(): bool
{
return $this->transactions;
return (bool) config('deploy-operations.transactions.enabled');
}

/**
* The number of attempts to execute a request within a transaction before throwing an error.
*/
public function transactionAttempts(): int
{
return $this->transactionAttempts;
return config('deploy-operations.transactions.attempts', 1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected bool $transactions = true;

public function up(): void
{
$this->table()->insert([
Expand All @@ -16,6 +14,11 @@ return new class extends Operation {
]);
}

public function enabledTransactions(): bool
{
return true;
}

protected function table()
{
return DB::table('transactions');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected bool $transactions = true;

public function up(): void
{
$this->table()->insert([
Expand All @@ -18,6 +16,11 @@ return new class extends Operation {
throw new Exception('Random message');
}

public function enabledTransactions(): bool
{
return true;
}

protected function table()
{
return DB::table('transactions');
Expand Down

0 comments on commit 7a967a8

Please sign in to comment.