serversideup / docker-php

🐳 Production-ready Docker images for PHP. Optimized for Laravel, WordPress, and more!
https://serversideup.net/open-source/docker-php/
GNU General Public License v3.0
1.65k stars 108 forks source link

Add creating missing SQLite database files #400

Open DarkGhostHunter opened 1 month ago

DarkGhostHunter commented 1 month ago

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:

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 commented 1 month ago

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 commented 1 month ago

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

jaydrogers commented 1 month ago

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 commented 1 month ago

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 https://github.com/laravel/framework/pull/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.