Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore migrations #34

Open
quentin-tdclic opened this issue Mar 4, 2022 · 1 comment
Open

Ignore migrations #34

quentin-tdclic opened this issue Mar 4, 2022 · 1 comment

Comments

@quentin-tdclic
Copy link

Hello,

I'm using Tenancy and I have a problem with your migrations.
When I do a "artisan migrate:fresh", I don't want your migrations to automatically be run (because I want them for each Tenant, not for the "central app").

Can you do something so we can :

  • publish migrations
  • prevent them from being run

Laravel Sanctum does it very well : https://laravel.com/docs/9.x/sanctum#migration-customization

Thanks !

@quentin-tdclic
Copy link
Author

I have a suggestion :
in bnbwebexpertise\laravel-attachments\src\AttachmentsServiceProvider.php

class AttachmentsServiceProvider extends ServiceProvider
{
    /**
     * Indicates if Attachments' migrations will be run.
     *
     * @var bool
     */
    public static $runsMigrations = true;

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        (...)

        if (self::shouldRunMigrations()) {
            $this->loadMigrationsFrom(__DIR__ . '/../migrations');
        }

        (...)
    }


    (...)


    /**
     * Determine if Attachments' migrations should be run.
     *
     * @return bool
     */
    public static function shouldRunMigrations()
    {
        return static::$runsMigrations;
    }

    /**
     * Configure Attachments to not register its migrations.
     *
     * @return static
     */
    public static function ignoreMigrations()
    {
        static::$runsMigrations = false;
    }
}

Usage :
in app\Providers\AppServiceProvider.php

use Bnb\Laravel\Attachments\AttachmentsServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    (...)

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        AttachmentsServiceProvider::ignoreMigrations();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant