Skip to content

Conversation

denistorresan
Copy link
Contributor

I found a problem when deploy for first run and an empty database when CACHE_STORE=database that fail the startup of the container.
The problem is located on deployment/start-container file, on initialStuff() function and it only happens when the database is empty / no tables.
In this case we get an error related to table not fund if we try to clear cache and optimize before full migration:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'myapp.cache' doesn't exist

So I placed the migrate command before the link / clear / optimize commands but I encountered a new error related to migration. In this case the switch --isolated try to query the cache store to lock the migration, but since the cache store is the database itself, it fail the migration with this new error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'myapp.cache_locks' doesn't exist (Connection: mysql, SQL: update cache_lockssetowner= ObdieQvOl9a8Bo1v,expiration= 1739793453 wherekey = framework/command-migrate and (owner= ObdieQvOl9a8Bo1v orexpiration<= 1739789853))

To avoid this problem I implemented sort of try/catch using || operators, in this case only for first time when the first migrate command fail, the second run correctly.

php artisan migrate --isolated --seed --force || php artisan migrate --seed --force

Container log (only on first startup without a database created) will look like the following screenshot:

immagine

@shahghasiadil
Copy link
Contributor

@denistorresan in this template redis already configured, I highly recommend it to use it instead of database caching.

@denistorresan
Copy link
Contributor Author

hi @shahghasiadil yes, this is true, and usually I use redis as a database caching. One small project for my customer does not use it and I encountered this issue.
With this patch we are always safe that any user setup works.

@smortexa smortexa merged commit 5641ab1 into exaco:main Feb 25, 2025
13 checks passed
@denistorresan denistorresan deleted the fix-cache-table-not-found-on-first-run branch May 9, 2025 10:19
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

Successfully merging this pull request may close these issues.

3 participants