fix cache and cache_lock table not found on first run #131
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_locksset
owner= ObdieQvOl9a8Bo1v,
expiration= 1739793453 where
key= framework/command-migrate and (
owner= ObdieQvOl9a8Bo1v or
expiration<= 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: