Laravel Migration Actions

Packages

December 23rd, 2021

Laravel Migration Actions

Laravel migration actions is like version control for your migration process, allowing your team to modify and share the application's actionable schema. If you have ever had to tell a teammate to perform any action on a production server manually, you've come across an issue that actions solve.

Actions are stored within a database/actions folder and operate similarly to the way migrations work. This package also includes an Artisan command to create new actions. Here's what an example action might look like:

1<?php
2 
3use DragonCode\LaravelActions\Support\Actionable;
4use Illuminate\Support\Facades\DB;
5 
6class ExampleAction extends Actionable
7{
8 protected $transactions = true;
9 
10 /**
11 * Run the actions.
12 *
13 * @return void
14 */
15 public function up(): void
16 {
17 DB::table('users')->insert([
18 'name' => 'Example User',
19 'email' => 'user@example.com',
20 'password' => bcrypt('password')
21 ]);
22 }
23 
24 /**
25 * Reverse the actions.
26 *
27 * @return void
28 */
29 public function down(): void
30 {
31 //
32 }
33}

Some of the packages main features include:

  • Ability to run actions every time you call migrate:actions command
  • Execution of actions only in specific environments
  • Exclude actions from specific environments
  • Easy database transactions in actions with configurable attempts before failing
  • Rolling back actions
  • Display the status of actions in the current environment

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.