PHPackages                             timokoerber/laravel-one-time-operations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. timokoerber/laravel-one-time-operations

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

timokoerber/laravel-one-time-operations
=======================================

Run operations once after deployment - just like you do it with migrations!

1.4.6(2mo ago)6481.7M—6.6%42[11 issues](https://github.com/TimoKoerber/laravel-one-time-operations/issues)[7 PRs](https://github.com/TimoKoerber/laravel-one-time-operations/pulls)7MITPHPPHP ^8.0

Since Mar 10Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/TimoKoerber/laravel-one-time-operations)[ Packagist](https://packagist.org/packages/timokoerber/laravel-one-time-operations)[ Docs](https://github.com/timokoerber/laravel-one-time-operations)[ RSS](/packages/timokoerber-laravel-one-time-operations/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (22)Used By (7)

[![One-Time Operations for Laravel](https://user-images.githubusercontent.com/65356688/225704995-ec7f54fb-a5b8-4d73-898f-2ebeed9ee733.jpg)](https://user-images.githubusercontent.com/65356688/225704995-ec7f54fb-a5b8-4d73-898f-2ebeed9ee733.jpg)

One-Time Operations for Laravel
===============================

[](#one-time-operations-for-laravel)

Run operations once after deployment - just like you do it with migrations!

---

**Take your CI/CD to the next Level with One-Time Operations for Laravel**! 🚀

Create specific classes for a one-time usage, that can be executed automatically after each deployment. Same as migrations they get processed once and then never again. Perfect for seeding or updating some data instantly after some database changes or feature updates.

This package is for you if...

- you regularly need to **update specific data** after you deployed new code
- you often execute jobs just **only one single time** after a deployment
- you sometimes **forget to execute** that one specific job and stuff gets crazy
- your code gets **cluttered with jobs**, that are not being used anymore
- your co-workers always need to be reminded to **execute that one job** after some database changes
- you often seed or process data **in a migration file** (which is a big no-no!)

Installation
------------

[](#installation)

Require this package with composer:

```
composer require timokoerber/laravel-one-time-operations
```

Create the required table in your database:

```
php artisan migrate
```

Now you're all set!

Commands
--------

[](#commands)

### Create operation files

[](#create-operation-files)

Create new operation file:

```
php artisan operations:make
```

Create file without any attributes:

```
php artisan operations:make  -e|--essential
```

Use command alias to create operation file:

```
php artisan make:operation
```

### Process operations

[](#process-operations)

Process all new operation files:

```
php artisan operations:process
```

Force synchronous execution:

```
php artisan operations:process --sync
```

Force asynchronous execution:

```
php artisan operations:process --async
```

Test mode (don't flag operations as processed):

```
php artisan operations:process --test
```

Run command isolated:

```
php artisan operations:process --isolated
```

Force a specific queue for the job:

```
php artisan operations:process --queue=
```

Only process operations with a specific tag:

```
php artisan operations:process --tag=
```

Re-run one specific operation:

```
php artisan operations:process
```

### Show operations

[](#show-operations)

Show all operations:

```
php artisan operations:show
```

Show pending operations:

```
php artisan operations:show pending
```

Show processed operations:

```
php artisan operations:show processed
```

Show disposed operations:

```
php artisan operations:show disposed
```

Use multiple filters to show operations:

```
php artisan operations:show pending processed disposed
```

Tutorials
---------

[](#tutorials)

### CI/CD &amp; Deployment-Process

[](#cicd--deployment-process)

The *One-Time Operations* work exactly like [Laravel Migrations](https://laravel.com/docs/9.x/migrations). Just process the operations *after your code was deployed and the migrations were migrated*. You can make it part of your deployment script like this:

```
...
 - php artisan migrate
 - php artisan operations:process
...
```

### Edit config

[](#edit-config)

By default, the following elements will be created in your project:

- the table `operations` in your database
- the directory `operations` in your project root directory

If you want to use a different settings just publish and edit the config file:

```
php artisan vendor:publish --provider="TimoKoerber\LaravelOneTimeOperations\Providers\OneTimeOperationsServiceProvider"
```

This will create the file `config/one-time-operations.php` with the following content.

```
// config/one-time-operation.php

return [
    'directory' => 'operations',
    'table' => 'operations',
];
```

Make changes as you like.

### Create One-Time Operation files

[](#create-one-time-operation-files)

[![One-Time Operations for Laravel - Create One-Time Operation files](https://user-images.githubusercontent.com/65356688/224433928-721b1261-b7ad-40c6-a512-d0f5b5fa0cbf.png)](https://user-images.githubusercontent.com/65356688/224433928-721b1261-b7ad-40c6-a512-d0f5b5fa0cbf.png)

[![One-Time Operations for Laravel - Create One-Time Operation files](https://user-images.githubusercontent.com/65356688/224433323-96b23e84-e22e-4333-8749-ae61cc866cd1.png)](https://user-images.githubusercontent.com/65356688/224433323-96b23e84-e22e-4333-8749-ae61cc866cd1.png)

To create a new operation file execute the following command:

```
php artisan operations:make AwesomeOperation
```

This will create a file like `operations/XXXX_XX_XX_XXXXXX_awesome_operation.php` with the following content.

```
