Skip to content

Conversation

@praem90
Copy link
Contributor

@praem90 praem90 commented Sep 14, 2025

📑 Description

This PR adds two Artisan commands

  1. Up
  2. Down
go run . artisan down
go run . artisan up

The down commands creates a temporary file in the framework storage folder
The up commands removes that file if exists

There is an another middleware CheckForMaintenance, that checks for the file.
It returns the request with 503 status code if the file exists else allow the request to passthrough.

Closes goravel/goravel#546

✅ Checks

  • [ x ] Added test cases for my code

@praem90 praem90 requested a review from a team as a code owner September 14, 2025 15:52
@codecov
Copy link

codecov bot commented Sep 14, 2025

Codecov Report

❌ Patch coverage is 88.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.97%. Comparing base (15cc675) to head (d9be037).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
foundation/console/down_command.go 90.00% 2 Missing and 1 partial ⚠️
foundation/console/up_command.go 85.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1198      +/-   ##
==========================================
- Coverage   68.55%   67.97%   -0.58%     
==========================================
  Files         228      235       +7     
  Lines       14588    14762     +174     
==========================================
+ Hits        10001    10035      +34     
- Misses       4229     4367     +138     
- Partials      358      360       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@almas-x
Copy link
Contributor

almas-x commented Sep 14, 2025

This is a fantastic PR with a very useful addition to the framework! 🎉

I have a suggestion: how about allowing an optional reason flag for the down command? This could record the reason or announcement for the maintenance, and store it in the framework/down file. The middleware could then read this reason and return it, making it available for APIsor views to display. This would enhance the user experience by providing more context during maintenance mode.


func (s *DownCommandTestSuite) TestHandle() {
app := mocksfoundation.NewApplication(s.T())
tmpfile := filepath.Join(os.TempDir(), "/down")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In unit tests, use t.TempDir() instead of os.TempDir().

t.TempDir() is preferred in unit tests because it creates a unique temporary directory for each test and automatically cleans it up after the test finishes. This helps prevent conflicts and side effects between tests, making your tests safer and more reliable.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Sep 15, 2025

Please fix the windows CI.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Sep 15, 2025

Thanks, great job 👍 Could add some related screenshots in the PR description?

func CheckForMaintenance() http.Middleware {
return func(ctx http.Context) {
if file.Exists(path.Storage("framework/down")) {
ctx.Request().AbortWithStatus(http.StatusServiceUnavailable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx.Request().AbortWithStatus(http.StatusServiceUnavailable)
ctx.Request().Abort(http.StatusServiceUnavailable)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// Handle Execute the console command.
func (r *DownCommand) Handle(ctx console.Context) error {
path := r.app.StoragePath("framework/down")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path := r.app.StoragePath("framework/down")
path := r.app.StoragePath("framework/maintenance")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// Extend The console command extend.
func (r *DownCommand) Extend() command.Extend {
return command.Extend{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you implement these options as well?

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is reason still required in this case? @almas-x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can implement those options @hwbrzzl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared to Laravel, the current implementation of reason is indeed a bit limited. I think we can refer to Laravel's implementation and support all the options in your screenshot except for the two that are crossed out.

Copy link
Contributor Author

@praem90 praem90 Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. What should be the response would be when no --render option is provided?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning the current logic should be fine.

@praem90 praem90 force-pushed the feat-546-artisan-command-up-and-down branch from 3479a4b to b70c346 Compare September 18, 2025 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ [Feature] artisan command up and down to set website Maintenance mode

3 participants