PHPackages                             pristavu/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. pristavu/laravel-one-time-operations

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

pristavu/laravel-one-time-operations
====================================

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

2.0.0(2y ago)0513MITPHPPHP ^8.0

Since Mar 28Pushed 2y agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

[![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)

```
php artisan operations:make                 // create new operation file
php artisan operations:make  -e|--essential // create file without any attributes
```

### Process operations

[](#process-operations)

```
php artisan operations:process                   // process all new operation files

php artisan operations:process --sync            // force synchronous execution
php artisan operations:process --async           // force asynchronous execution
php artisan operations:process --test            // dont flag operations as processed
php artisan operations:process --isolated        // run command isolated

php artisan operations:process --queue=    // force queue, that the job will be dispatched to
php artisan operations:process --tag=   // only process operations, that have the given tag

php artisan operations:process   // re-run one specific operation
```

### Show operations

[](#show-operations)

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

php artisan operations:show pending processed disposed  // use multiple filters
```

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.

```
