tenancy icon indicating copy to clipboard operation
tenancy copied to clipboard

[4.x] Add command to bring the tenants up and down from maintenance and remove deprecated exception

Open stein-j opened this issue 4 years ago • 19 comments

This PR changes the maintenance mode to comply to the changes made in Laravel 8.

New

  • Adds two CLI commands to the package: tenancy:up and tenancy:down with the same parameters as the default Laravel command except for the option render because it is not possible to render a page before Laravel is booted for a specific tenant.

  • Adds the function bringUpFromMaintenance in the trait MaintenanceMode.

Changes

A tenant in maintenance mode now throws an HttpException exception instead of the deprecated MaintenanceModeException exception.

Closes #533.

stein-j avatar Dec 02 '21 21:12 stein-j

Hey. This looks good, thanks for the contribution! I think I had some maintenance mode related tasks written in my backlog for v4, so I'll probably merge this when working on the feature. Should be in January I think.

stancl avatar Dec 06 '21 12:12 stancl

Codecov Report

Merging #761 (7875fbd) into 3.x (20e1fa1) will decrease coverage by 1.39%. The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x     #761      +/-   ##
============================================
- Coverage     87.02%   85.62%   -1.40%     
- Complexity      372      375       +3     
============================================
  Files           103      105       +2     
  Lines          1102     1120      +18     
============================================
  Hits            959      959              
- Misses          143      161      +18     
Impacted Files Coverage Δ
src/Commands/Down.php 0.00% <0.00%> (ø)
src/Commands/Up.php 0.00% <0.00%> (ø)
src/Database/Concerns/MaintenanceMode.php 75.00% <0.00%> (-25.00%) :arrow_down:
src/TenancyServiceProvider.php 96.66% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 20e1fa1...7875fbd. Read the comment docs.

codecov-commenter avatar Dec 25 '21 16:12 codecov-commenter

Closing #757 and will finish that here. We could probably add --secret but I'm not sure if there's a point in having a different secret than the central app.

stancl avatar Dec 25 '21 16:12 stancl

Laravel now simply throws a HttpException exception. https://github.com/laravel/framework/blob/8f3b411969ffdd733a0ba54098e08f8ca7c1369e/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php#L78

If you give me a few days, I can update the code and comply to the new maintenance mode used by Laravel and then update the commands so that we can use the same parameters as Laravel. I think all parameters can be recreated except for render because this allows to return a response even before Laravel is initialised (which means, before the package is also initialised).

Note: Naturally this would allow #757

stein-j avatar Dec 25 '21 18:12 stein-j

Sure, thanks a lot for the work on this! FWIW if there's a signature change, you can use the version in Laravel 9. And probably change the target to the master branch.

stancl avatar Dec 25 '21 19:12 stancl

I'm glade you mentioned Laravel 9 because coincidently two PRs (1, 2) have been accepted during those last few days and it changed the maintenance system.

L9 will now have a configurable driver for the maintenance storage system (which will determine how and where the data is stored), at the time of writing this comment there are two drivers/managers file: Which is the old way to put the application to maintenance ; cache : Which will store the data inside the cache.

The reason they added drivers, is because when using a load balancer and you set the application into maintenance mode it would only work on the application the command has been typed on... so a cache driver was needed. But this package doesn't need such implementation because even if you would use a load balancer, there should be only one database connection per tenant for all applications (at least in most use cases).

So I think to keep things simple, this PR will keep its own feature and keep storing the data in the database. It might be important to mention in the documentation that the maintenance mode doesn't uses the driver from the config file.

Maybe in another PR we can try to create our custom driver, tenant compatible.

stein-j avatar Dec 26 '21 15:12 stein-j

this PR will keep its own feature and keep storing the data in the database

That is in the data column in our case, right?

stancl avatar Dec 26 '21 16:12 stancl

Yes

stein-j avatar Dec 26 '21 17:12 stein-j

Just a note: the tests will fail because master has some failing tests due to dependencies that need new syntax. But we can look at this feature's tests in isolation

stancl avatar Jan 06 '22 16:01 stancl

@stancl the PR is done and all the tests have been added. As you said there are conflict versions with composer, so the tests fails. Do you want me to look into it ? Or should we wait that the master to be updated ?

stein-j avatar Feb 20 '22 10:02 stein-j

Probably wait until master is updated 👍🏻

When we add L9 support, I'll merge 3.x into master

stancl avatar Feb 20 '22 11:02 stancl

Hello @stancl,

I just realized that the changes from this PR are not compatible with Laravel 6 & 7. I've put this PR back to draft, ping me when you start working on the V4 and I'll see what can be done at that point.

stein-j avatar Mar 08 '22 15:03 stein-j

@lukinovec I think we should finish this PR before the pending tenants since it's smaller and it interacts with the trait adding a --tenants option. That way we'll make the conflict resolution simpler.

Also, the tests are showing as failing, but I think they'll run differently when the CI is triggered again since I simplified the CI matrix in the master branch. So if you could resolve the conflicts, that would trigger a CI build and we'll see how the feature works now.

stancl avatar Jul 27 '22 11:07 stancl

Only php-cs-fixer is failing, tests seem to be passing, so CI-wise this PR is ready now.

I'll look at the code now and see if this is ready to be merged.

stancl avatar Aug 01 '22 15:08 stancl

@stein-j Is anything unimplemented yet or is the PR fully ready? Is the code made to work with Laravel 9 (the changes you made to the way tenants are put into maintenance mode)?

stancl avatar Aug 01 '22 15:08 stancl

@stancl I want to go over it again, it's been a while and a file was changed in another PR since (https://github.com/archtechx/tenancy/pull/802/files#diff-40487242039e9842dc87ba96285282e42d0cc5b9a7dbeac6f115c4ee2bb8db59). Let me get back to you in a few hours.

stein-j avatar Aug 01 '22 16:08 stein-j

@stancl what will be the minimum requirements for Laravel and PHP for V4 ?

stein-j avatar Aug 01 '22 17:08 stein-j

Just that the syntax is updated for Laravel 9. I think you already did this since the PR is recent. But I'm just checking in case anything is missing.

stancl avatar Aug 01 '22 17:08 stancl

Ok, it's all good.

stein-j avatar Aug 01 '22 21:08 stein-j

FYI I merged master into this so you should delete the 3.x branch after we merge this since it isn't compatible with our 3.x (in case you plan on making PRs to 3.x in the future)

stancl avatar Sep 29 '22 13:09 stancl

Thanks for your work on this PR!

stancl avatar Sep 29 '22 14:09 stancl