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

Document using --skip-failing on tenants:migrate #73

Closed
xdimension opened this issue Jul 13, 2020 · 3 comments
Closed

Document using --skip-failing on tenants:migrate #73

xdimension opened this issue Jul 13, 2020 · 3 comments
Assignees

Comments

@xdimension
Copy link

Hi,

First, thank you for creating this awesome package!

Describe the bug

In our case when a tenant is created a record will be added to the Tenant table but we need to postpone the creation of the tenant database as it requires approval (we have managed this behavior using additional event instead of TenantCreated, thanks for the flexibility of this package). Thus, there will be any tenant records which the databases haven't been created yet, this causes an issue if we have additional migration for tenants, when running artisan tenants:migrate it will raise TenantDatabaseDoesNotExistException.

 at \vendor\stancl\tenancy\src\Bootstrappers\DatabaseTenancyBootstrapper.php:30
    27|         if (app()->environment('local')) {
    28|             $database = $tenant->database()->getName();
    29|             if (! $tenant->database()->manager()->databaseExists($database)) {
  > 30|                 throw new TenantDatabaseDoesNotExistException($database);
    31|             }
    32|         }

Steps to reproduce

Specifically for my case above, running artisan tenants:migrate will raise TenantDatabaseDoesNotExistException.

Expected behavior

It may show just a message that the database doesn't exist and continue the migration for the rest of the other tenants.

Your setup

  • Laravel version: 7.0
  • stancl/tenancy version: 3.0
  • Storage driver: mysql
@tfilho
Copy link

tfilho commented Jul 13, 2020

This could be configurable

@stancl
Copy link
Owner

stancl commented Jul 13, 2020

Hi.

This is not a bug. The standard behavior works as it should.

If you have tenants that don't have a database yet, don't run tenants:migrate for all tenants. You can specify the tenants for which you want the command to run.

Ideally, you'd run it for each tenant separately from the app.

I can see this being an issue with deployments. Tenants existing without a DB but tenants:migrate running.

I think the best thing to do here would be adding a flag to tenants:migrate like --skip-failing. It could catch the exception from DatabaseTenancyBootstrapper and simply do nothing.

But, note that the TenantDatabaseDoesNotExistException is only thrown in local environment. In production, you get a QueryException.

Feel free to send a PR.

@xdimension
Copy link
Author

Thanks for your response. Sorry for filing this issue as a bug, was not sure where to put in.

Yes, I think it's a good idea to add --skip-failing flag to tenant migration command. Let's see if we can explore the package and make the PR.

@stancl stancl closed this as completed Aug 31, 2020
@stancl stancl changed the title Exception for any tenant which the database doesn't exist Document using --skip-failing on tenants:migrate Aug 31, 2020
@stancl stancl reopened this Aug 31, 2020
@stancl stancl transferred this issue from archtechx/tenancy Aug 31, 2020
@stancl stancl mentioned this issue Jun 4, 2022
@stancl stancl closed this as completed Jun 4, 2022
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

3 participants