Skip to content

Conversation

@DarkGhostHunter
Copy link

@DarkGhostHunter DarkGhostHunter commented Jul 11, 2024

This PR allows the container to start and create missing the SQLite databases set by the application.

It's part of the container AUTORUN_LARAVEL scripts. It runs before the migrations. Is opt-in by default, mostly because usually production apps run on non-SQLite but PR/preview/staging apps sometimes do spin SQLite for testing or pure convenience.

The way it works is through the AUTORUN_LARAVEL_TOUCH_SQLITE environment value, which by default is false:

  • When true, 1 or default, it will pick the default connection.
  • When used as default, telescope, custom, it will find the connection names, and create each database file.

This is done by checking if the driver is sqlite and the file doesn't exist. If it's not SQLite, it fails. If the database file already exists, doesn't do anything.

Note

Newer Laravel versions do create the SQLite database file when force migrating. Outside that command, it won't.

@jaydrogers
Copy link
Member

Thanks for the PR on this. I just ran into this issue myself.

Regarding your comment:

Newer Laravel versions do create the SQLite database file when force migrating. Otherwise, it won't.

Do you know what version this started happening in?

@DarkGhostHunter
Copy link
Author

I believe 9.x or 8.x, I'll have to see the blame.

@jaydrogers
Copy link
Member

Thanks!

If it goes back that far with Laravel, should we even merge this?

I was able to resolve my issue by having proper permissions on my Docker Volumes with Laravel 11. Once I had the correct permissions, the auomations worked perfectly and created my database.

@DarkGhostHunter
Copy link
Author

Thanks!

If it goes back that far with Laravel, should we even merge this?

I was able to resolve my issue by having proper permissions on my Docker Volumes with Laravel 11. Once I had the correct permissions, the auomations worked perfectly and created my database.

9.31 laravel/framework#44153

It doesn't go that far IMHO. In any case, I think older Laravel apps would benefit from this on staging and development, especially if you are on the path to upgrade.

@jaydrogers
Copy link
Member

Thanks for your efforts on this PR!

As I mentioned in the other post, I spent a ton of time refactoring the Laravel Automations script:

What's new in my refactor

I decided to NOT include a "touch" for creating SQLite database file.

My reason

Laravel will create this for you automatically with php artisan migrate. I did not want to step on Laravel's toes with this process.

Instead, you can see that I added helpful logic to help debug if a SQLite file does not exist when we test the DB connection: https://github.com/serversideup/docker-php/blob/280-create-a-frankenphp-variation/src/common/etc/entrypoint.d/lib/laravel/test-db-connection.php

Let me know your thoughts on my approach. I greatly appreciate your intentions on this PR and would gladly review any other improvements that you suggest 👍

@jaydrogers jaydrogers closed this Oct 7, 2025
@github-project-automation github-project-automation bot moved this from 🤔 Evaluating to Done in serversideup/php v4.0 Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants