shrink/conductor-laravel

Laravel runtime dependency checks for Conductor

v2.0.0 2022-05-15 17:21 UTC

This package is auto-updated.

Last update: 2024-10-15 22:35:06 UTC


README

Packagist

Conductor checks the status of runtime dependencies, Conductor: Laravel is a set of Laravel runtime dependency checks.

Scenario: I have a containerised Laravel application, I want to deploy a new version which includes database migrations. How do I prevent the new version from running against a database that has yet to be migrated?

Usage

  1. Install the library with composer
  2. Enable Conductor with the optional Service Provider
  3. Define your application's runtime dependencies

↓ Jump to Dependencies available for Laravel

Install

dev:~$ composer require shrink/conductor-laravel

Enable

An optional out-of-the-box Service Provider registers the necessary instances (with sane default configuration) in the Laravel container.

'providers' => [
    // ...
+   Shrink\Conductor\Laravel\Conductor::class,
    // ...
];

Define Dependencies

Add a Dependency to the Collection with a string id and an instance of a Shrink\Conductor\ChecksDependencyStatus. For example, to register a Database Schema dependency identified by schema:

$checks = $app->make(CollectsApplicationDependencyChecks::class);

$checks->addDependencyCheck(
    'schema',
    $app->make(\Shrink\Conductor\Laravel\Dependencies\DatabaseSchema::class)
);

Supported Dependency Checks

Database Schema

Database Schema checks that the connected database is running a compatible version of the database schema. A database schema is compatible when every migration (on the filesystem) has been applied to the database.

Depends on a lcobucci/clock implementation.

use Illuminate\Database\Migrations\Migrator;
use Lcobucci\Clock\Clock;
use Shrink\Conductor\Laravel\Dependencies\DatabaseSchema;

new DatabaseSchema(
    $app->make(Migrator::class, 'migrator'),
    (string) $app->basePath('database/migrations'),
    $app->make(Clock::class)
);

Development

Hooks

A pre-commit Git Hook is included for ensuring compliance with code requirements on commit, enable the Git Hook by running the following command:

dev:~$ git config core.hooksPath .github/hooks

License

Conductor: Laravel is open-sourced software licensed under the MIT license.